Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Microsoft/visualfsharp into tgv2
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/fsharp/NameResolution.fs
  • Loading branch information
forki committed Oct 1, 2018
2 parents a64629b + ede7902 commit f10d9ef
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 79 deletions.
28 changes: 5 additions & 23 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,11 @@ let unsplitTypeName (ns, n) =
| [] -> String.concat "." ns + "." + n
| _ -> n

let splitTypeNameRightAux nm =
if String.contains nm '.' then
let idx = String.rindex nm '.'
let s1, s2 = splitNameAt nm idx
Some s1, s2
else None, nm
let splitTypeNameRightAux (nm:string) =
let idx = nm.LastIndexOf '.'
if idx = -1 then None, nm else
let s1, s2 = splitNameAt nm idx
Some s1, s2

let splitTypeNameRight nm =
memoizeNamespaceRightTable.GetOrAdd(nm, splitTypeNameRightAux)
Expand Down Expand Up @@ -4189,23 +4188,6 @@ let resolveILMethodRef td mref = resolveILMethodRefWithRescope id td mref
let mkRefToILModule m =
ILModuleRef.Create(m.Name, true, None)


let ungenericizeTypeName n =
let sym = '`'
if
String.contains n sym &&
(* check what comes after the symbol is a number *)
(let m = String.rindex n sym
let res = ref (m < n.Length - 1)
for i = m + 1 to n.Length - 1 do
res := !res && n.[i] >= '0' && n.[i] <= '9'
!res)
then
let pos = String.rindex n sym
String.sub n 0 pos
else n


type ILEventRef =
{ erA: ILTypeRef; erB: string }
static member Create(a, b) = {erA=a;erB=b}
Expand Down
3 changes: 0 additions & 3 deletions src/absil/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1540,9 +1540,6 @@ val typeNameForGlobalFunctions: string

val isTypeNameForGlobalFunctions: string -> bool

val ungenericizeTypeName: string -> string (* e.g. List`1 --> List *)


// ====================================================================
// PART 2
//
Expand Down
12 changes: 1 addition & 11 deletions src/absil/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -452,23 +452,13 @@ type String with
member inline x.EndsWithOrdinal(value) =
x.EndsWith(value, StringComparison.Ordinal)

module String =
let indexNotFound() = raise (new KeyNotFoundException("An index for the character was not found in the string"))

module String =
let make (n: int) (c: char) : string = new String(c, n)

let get (str:string) i = str.[i]

let sub (s:string) (start:int) (len:int) = s.Substring(start,len)

let index (s:string) (c:char) =
let r = s.IndexOf(c)
if r = -1 then indexNotFound() else r

let rindex (s:string) (c:char) =
let r = s.LastIndexOf(c)
if r = -1 then indexNotFound() else r

let contains (s:string) (c:char) = s.IndexOf(c) <> -1

let order = LanguagePrimitives.FastGenericComparer<string>
Expand Down
4 changes: 2 additions & 2 deletions src/buildfromsource/FSharp.Compiler.Private/FSComp.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3082,7 +3082,7 @@
<value>This number is outside the allowable range for 32-bit floats</value>
</data>
<data name="lexInvalidNumericLiteral" xml:space="preserve">
<value>This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0b0001 (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger).</value>
<value>This is not a valid numeric literal. Valid numeric literals include 1, 0x1, 0b0001 (int), 1u (uint32), 1L (int64), 1UL (uint64), 1s (int16), 1us (uint16), 1y (sbyte), 1uy (byte), 1.0 (float), 1.0f (float32), 1.0m (decimal), 1I (BigInteger).</value>
</data>
<data name="lexInvalidByteLiteral" xml:space="preserve">
<value>This is not a valid byte literal</value>
Expand Down Expand Up @@ -4360,4 +4360,4 @@
<data name="tcTypeDoesNotInheritAttribute" xml:space="preserve">
<value>This type does not inherit Attribute, it will not work correctly with other .NET languages.</value>
</data>
</root>
</root>
10 changes: 5 additions & 5 deletions src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2609,13 +2609,13 @@ type TcConfigBuilder =
member tcConfigB.RemoveReferencedAssemblyByPath (m, path) =
tcConfigB.referencedDLLs <- tcConfigB.referencedDLLs |> List.filter (fun ar-> ar.Range <> m || ar.Text <> path)

static member SplitCommandLineResourceInfo ri =
if String.contains ri ',' then
let p = String.index ri ','
static member SplitCommandLineResourceInfo (ri:string) =
let p = ri.IndexOf ','
if p <> -1 then
let file = String.sub ri 0 p
let rest = String.sub ri (p+1) (String.length ri - p - 1)
if String.contains rest ',' then
let p = String.index rest ','
let p = rest.IndexOf ','
if p <> -1 then
let name = String.sub rest 0 p+".resources"
let pubpri = String.sub rest (p+1) (rest.Length - p - 1)
if pubpri = "public" then file, name, ILResourceAccess.Public
Expand Down
22 changes: 13 additions & 9 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -982,10 +982,8 @@ type TypeNameResolutionStaticArgsInfo =

// Get the first possible mangled name of the type, assuming the args are generic args
member x.MangledNameForType nm =
if IsMangledGenericName nm || x.NumStaticArgs = 0 then nm
else nm+"`"+string x.NumStaticArgs


if x.NumStaticArgs = 0 || TryDemangleGenericNameAndPos nm <> ValueNone then nm
else nm + "`" + string x.NumStaticArgs

[<NoEquality; NoComparison>]
/// Represents information which guides name resolution of types.
Expand Down Expand Up @@ -1015,7 +1013,11 @@ let LookupTypeNameInEntityHaveArity nm (staticResInfo: TypeNameResolutionStaticA
/// Unqualified lookups of type names where the number of generic arguments is known
/// from context, e.g. List<arg>. Rebindings due to 'open' may have rebound identifiers.
let LookupTypeNameInEnvHaveArity fq nm numTyArgs (nenv:NameResolutionEnv) =
let key = if IsMangledGenericName nm then DecodeGenericTypeName nm else NameArityPair(nm,numTyArgs)
let key =
match TryDemangleGenericNameAndPos nm with
| ValueSome pos -> DecodeGenericTypeName pos nm
| _ -> NameArityPair(nm,numTyArgs)

match nenv.TyconsByDemangledNameAndArity(fq).TryFind key with
| None -> nenv.TyconsByAccessNames(fq).TryFind nm |> Option.map List.head
| res -> res
Expand All @@ -1037,15 +1039,17 @@ let LookupTypeNameInEnvHaveArity fq nm numTyArgs (nenv:NameResolutionEnv) =
// In theory the full names such as ``RecordType`1`` can
// also be used to qualify access if needed, though this is almost never needed.

let LookupTypeNameNoArity nm (byDemangledNameAndArity: LayeredMap<NameArityPair,_>) (byAccessNames: LayeredMultiMap<string,_>) =
if IsMangledGenericName nm then
match byDemangledNameAndArity.TryGetValue (DecodeGenericTypeName nm) with
let LookupTypeNameNoArity nm (byDemangledNameAndArity: LayeredMap<NameArityPair,_>) (byAccessNames: LayeredMultiMap<string,_>) =
match TryDemangleGenericNameAndPos nm with
| ValueSome pos ->
let demangled = DecodeGenericTypeName pos nm
match byDemangledNameAndArity.TryGetValue demangled with
| true, res -> [res]
| _ ->
match byAccessNames.TryGetValue nm with
| true, res -> res
| _ -> []
else
| _ ->
byAccessNames.[nm]

/// Qualified lookup of type names in the environment
Expand Down
6 changes: 3 additions & 3 deletions src/fsharp/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ module private PrintIL =
open Microsoft.FSharp.Compiler.AbstractIL.IL

let fullySplitILTypeRef (tref:ILTypeRef) =
(List.collect IL.splitNamespace (tref.Enclosing @ [IL.ungenericizeTypeName tref.Name]))
(List.collect IL.splitNamespace (tref.Enclosing @ [PrettyNaming.DemangleGenericTypeName tref.Name]))

let layoutILTypeRefName denv path =
let path =
Expand Down Expand Up @@ -193,7 +193,7 @@ module private PrintIL =
let args = signatur.ArgTypes |> List.map (layoutILType denv ilTyparSubst)
let res =
match cons with
| Some className -> layoutILTypeRefName denv (SplitNamesForILPath (ungenericizeTypeName className)) ^^ (pruneParms className ilTyparSubst |> paramsL) // special case for constructor return-type (viz., the class itself)
| Some className -> layoutILTypeRefName denv (SplitNamesForILPath (PrettyNaming.DemangleGenericTypeName className)) ^^ (pruneParms className ilTyparSubst |> paramsL) // special case for constructor return-type (viz., the class itself)
| None -> signatur.ReturnType |> layoutILType denv ilTyparSubst
match args with
| [] -> WordL.structUnit ^^ WordL.arrow ^^ res
Expand Down Expand Up @@ -226,7 +226,7 @@ module private PrintIL =
// return type be passed along as the `cons` parameter.)
let res =
match cons with
| Some className -> layoutILTypeRefName denv (SplitNamesForILPath (ungenericizeTypeName className)) ^^ (pruneParms className ilTyparSubst |> paramsL) // special case for constructor return-type (viz., the class itself)
| Some className -> layoutILTypeRefName denv (SplitNamesForILPath (PrettyNaming.DemangleGenericTypeName className)) ^^ (pruneParms className ilTyparSubst |> paramsL) // special case for constructor return-type (viz., the class itself)
| None -> retType |> layoutILType denv ilTyparSubst
match parameters with
| [] -> WordL.structUnit ^^ WordL.arrow ^^ res
Expand Down
46 changes: 26 additions & 20 deletions src/fsharp/PrettyNaming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -484,30 +484,36 @@ module public Microsoft.FSharp.Compiler.PrettyNaming

let [<Literal>] private mangledGenericTypeNameSym = '`'

let IsMangledGenericName (n:string) =
n.IndexOf mangledGenericTypeNameSym <> -1 &&
let TryDemangleGenericNameAndPos (n:string) =
(* check what comes after the symbol is a number *)
let m = n.LastIndexOf mangledGenericTypeNameSym
let mutable res = m < n.Length - 1
for i = m + 1 to n.Length - 1 do
res <- res && n.[i] >= '0' && n.[i] <= '9'
res
let pos = n.LastIndexOf mangledGenericTypeNameSym
if pos = -1 then ValueNone else
let mutable res = pos < n.Length - 1
let mutable i = pos + 1
while res && i < n.Length do
let char = n.[i]
if not (char >= '0' && char <= '9') then
res <- false
i <- i + 1
if res then
ValueSome pos
else
ValueNone

type NameArityPair = NameArityPair of string * int

let DecodeGenericTypeName n =
if IsMangledGenericName n then
let pos = n.LastIndexOf mangledGenericTypeNameSym
let res = n.Substring(0,pos)
let num = n.Substring(pos+1,n.Length - pos - 1)
NameArityPair(res, int32 num)
else NameArityPair(n,0)

let DemangleGenericTypeName n =
if IsMangledGenericName n then
let pos = n.LastIndexOf mangledGenericTypeNameSym
n.Substring(0,pos)
else n
let DecodeGenericTypeName pos (mangledName:string) =
let res = mangledName.Substring(0,pos)
let num = mangledName.Substring(pos+1,mangledName.Length - pos - 1)
NameArityPair(res, int32 num)

let DemangleGenericTypeNameWithPos pos (mangledName:string) =
mangledName.Substring(0,pos)

let DemangleGenericTypeName (mangledName:string) =
match TryDemangleGenericNameAndPos mangledName with
| ValueSome pos -> DemangleGenericTypeNameWithPos pos mangledName
| _ -> mangledName

let private chopStringTo (s:string) (c:char) =
match s.IndexOf c with
Expand Down
7 changes: 4 additions & 3 deletions src/fsharp/tast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -480,10 +480,11 @@ let KeyTyconByDemangledNameAndArity nm (typars: _ list) x =

/// Generic types can be accessed either by 'List' or 'List`1'. This lists both keys. The second form should really be deprecated.
let KeyTyconByAccessNames nm x =
if IsMangledGenericName nm then
let dnm = DemangleGenericTypeName nm
match TryDemangleGenericNameAndPos nm with
| ValueSome pos ->
let dnm = DemangleGenericTypeNameWithPos pos nm
[| KeyValuePair(nm,x); KeyValuePair(dnm,x) |]
else
| _ ->
[| KeyValuePair(nm,x) |]

type ModuleOrNamespaceKind =
Expand Down

0 comments on commit f10d9ef

Please sign in to comment.