Skip to content

Commit e0590b2

Browse files
Merge pull request #2297 from fable-compiler/entity-by-core-name
RC 9
2 parents 820ed87 + 79e6928 commit e0590b2

28 files changed

+411
-298
lines changed

src/Fable.AST/Fable.AST.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
77
<GenerateDocumentationFile>true</GenerateDocumentationFile>
88
<Version>3.0.0</Version>
9-
<PackageVersion>3.0.0-nagareyama-beta-002</PackageVersion>
9+
<PackageVersion>3.0.0-nagareyama-rc-001</PackageVersion>
1010
</PropertyGroup>
1111
<ItemGroup>
1212
<Compile Include="Common.fs" />

src/Fable.AST/Fable.fs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ namespace rec Fable.AST.Fable
22

33
open Fable.AST
44

5+
type EntityPath =
6+
| SourcePath of string
7+
| AssemblyPath of string
8+
/// Only used to reference entities in core assemblies without a path
9+
| CoreAssemblyName of string
10+
511
type EntityRef =
6-
{ QualifiedName: string
7-
SourcePath: string option }
8-
member this.FullName =
9-
let fullName =
10-
match this.QualifiedName.IndexOf(",") with
11-
| i when i > 0 -> this.QualifiedName.[..i-1]
12-
| _ -> this.QualifiedName
13-
fullName.Replace("+", ".")
12+
{ FullName: string
13+
Path: EntityPath }
14+
member this.SourcePath =
15+
match this.Path with
16+
| SourcePath p -> Some p
17+
| AssemblyPath _ | CoreAssemblyName _ -> None
1418

1519
type DeclaredType =
1620
abstract Entity: EntityRef
@@ -305,7 +309,8 @@ type Expr =
305309
| DecisionTreeSuccess of targetIndex: int * boundValues: Expr list * Type
306310

307311
// Getters, setters and bindings
308-
| Let of bindings: (Ident * Expr) list * body: Expr
312+
| Let of Ident * Expr * body: Expr
313+
| LetRec of bindings: (Ident * Expr) list * body: Expr
309314
| Get of Expr * GetKind * typ: Type * range: SourceLocation option
310315
| Set of Expr * key: KeyKind option * value: Expr * range: SourceLocation option
311316

@@ -335,7 +340,8 @@ type Expr =
335340
| WhileLoop _
336341
| ForLoop _-> Unit
337342
| Sequential exprs -> List.tryLast exprs |> Option.map (fun e -> e.Type) |> Option.defaultValue Unit
338-
| Let (_, expr)
343+
| Let (_, _, expr)
344+
| LetRec (_, expr)
339345
| TryCatch (expr, _, _, _)
340346
| IfThenElse (_, expr, _, _)
341347
| DecisionTree (expr, _) -> expr.Type
@@ -347,6 +353,7 @@ type Expr =
347353
| ObjectExpr _
348354
| Sequential _
349355
| Let _
356+
| LetRec _
350357
| DecisionTree _
351358
| DecisionTreeSuccess _ -> None
352359
| Lambda (_, e, _)

src/Fable.AST/Plugins.fs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ type PluginHelper =
2828
abstract GetRootModule: fileName: string -> string
2929
abstract GetEntity: EntityRef -> Entity
3030

31+
[<System.AttributeUsage(System.AttributeTargets.Assembly)>]
32+
type ScanForPluginsAttribute() =
33+
inherit System.Attribute()
34+
3135
[<AbstractClass>]
3236
type PluginAttribute() =
3337
inherit System.Attribute()
@@ -36,5 +40,5 @@ type PluginAttribute() =
3640
[<AbstractClass>]
3741
type MemberDeclarationPluginAttribute() =
3842
inherit PluginAttribute()
39-
abstract Transform: PluginHelper * MemberDecl -> MemberDecl
43+
abstract Transform: PluginHelper * File * MemberDecl -> MemberDecl
4044
abstract TransformCall: PluginHelper * member_: MemberFunctionOrValue * expr: Expr -> Expr

src/Fable.AST/RELEASE_NOTES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
### 3.0.0-nagareyama-rc-001
2+
3+
* Add `Expr.LetRec`
4+
* Add `ScanForPluginsAttribute`
5+
* Add `AST.Fable.File` argument to `MemberDeclarationPlugin.Transform`
6+
17
### 3.0.0-nagareyama-beta-002
28

39
* Add `MemberDecl.ExportDefault`

src/Fable.Cli/Entry.fs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,17 @@ let defaultFileExt isTypescript args =
8282

8383
type Runner =
8484
static member Run(args: string list, rootDir: string, runProc: RunProcess option, ?fsprojPath: string, ?watch, ?testInfo) =
85-
let makeAbsolute (path: string) =
86-
if IO.Path.IsPathRooted(path) then path
87-
else IO.Path.Combine(rootDir, path)
85+
let normalizeAbsolutePath (path: string) =
86+
(if IO.Path.IsPathRooted(path) then path
87+
else IO.Path.Combine(rootDir, path))
88+
// Use GetFullPath to remove things like: myrepo/./build/
89+
|> Path.normalizeFullPath
8890

8991
let watch = defaultArg watch false
9092

9193
let fsprojPath =
9294
fsprojPath
93-
|> Option.map makeAbsolute
95+
|> Option.map normalizeAbsolutePath
9496
|> Option.defaultValue rootDir
9597

9698
if IO.Directory.Exists(fsprojPath) then
@@ -147,7 +149,7 @@ type Runner =
147149
{ ProjectFile = Path.normalizeFullPath projFile
148150
FableLibraryPath = argValue "--fableLib" args
149151
RootDir = rootDir
150-
OutDir = argValueMulti ["-o"; "--outDir"] args |> Option.map makeAbsolute
152+
OutDir = argValueMulti ["-o"; "--outDir"] args |> Option.map normalizeAbsolutePath
151153
ForcePkgs = flagEnabled "--forcePkgs" args
152154
NoRestore = flagEnabled "--noRestore" args
153155
Exclude = argValue "--exclude" args

src/Fable.Cli/Fable.Cli.fsproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<Version>3.0.0</Version>
7-
<PackageVersion>3.0.0-nagareyama-rc-008</PackageVersion>
7+
<PackageVersion>3.0.0-nagareyama-rc-009</PackageVersion>
88
<!-- Allow users with newer dotnet SDK to run Fable, see #1910 -->
99
<RollForward>Major</RollForward>
1010
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
@@ -18,9 +18,6 @@
1818
<Content Include="..\..\build\fable-library\**\*.js" PackagePath="fable-library\" />
1919
</ItemGroup>
2020
<ItemGroup>
21-
<Compile Include="..\fable-standalone\src\Metadata.fs">
22-
<Link>Metadata.fs</Link>
23-
</Compile>
2421
<Compile Include="Util.fs" />
2522
<Compile Include="Contributors.fs" />
2623
<Compile Include="Globbing.fs" />

src/Fable.Cli/ProjectCracker.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ let getProjectOptionsFromScript (opts: CrackerOptions): CrackedFsproj list * Cra
175175
dllRefs, path::srcFiles
176176
| _ -> dllRefs, srcFiles)
177177

178-
let coreDllDir = IO.Path.GetDirectoryName(typeof<System.Array>.Assembly.Location) |> Path.normalizePath
178+
let coreDllDir = IO.Path.GetDirectoryName(typeof<Array>.Assembly.Location) |> Path.normalizePath
179179
let fsharpCoreDll = typeof<obj list>.Assembly.Location |> Path.normalizePath
180180

181181
let coreDlls =
182-
Standalone.Metadata.references_core
182+
Metadata.coreAssemblies
183183
|> Array.filter (function
184184
| "FSharp.Core" | "Fable.Core" -> false
185185
| _ -> true)
@@ -278,7 +278,7 @@ let private isUsefulOption (opt : string) =
278278
[ "--define"
279279
"--nowarn"
280280
"--warnon"
281-
"--warnaserror"
281+
// "--warnaserror" // Disable for now to prevent unexpected errors, see #2288
282282
// "--langversion" // See getBasicCompilerArgs
283283
]
284284
|> List.exists opt.StartsWith
@@ -433,7 +433,7 @@ let createFableDir (opts: CrackerOptions) =
433433
let compilerInfo = IO.Path.Combine(fableDir, "compiler_info.txt")
434434
let newInfo =
435435
Map [
436-
"version", Fable.Literals.VERSION
436+
"version", Literals.VERSION
437437
"define", opts.FableOptions.Define |> List.sort |> String.concat ","
438438
"typedArrays", opts.FableOptions.TypedArrays.ToString()
439439
"clampByteArrays", opts.FableOptions.ClampByteArrays.ToString()
@@ -543,7 +543,7 @@ let getFullProjectOpts (opts: CrackerOptions) =
543543
|> List.toArray
544544

545545
let otherOptions =
546-
let coreRefs = HashSet Standalone.Metadata.references_core
546+
let coreRefs = HashSet Metadata.coreAssemblies
547547
coreRefs.Add("System.Private.CoreLib") |> ignore
548548
let ignoredRefs = HashSet [
549549
"WindowsBase"

src/Fable.Cli/RELEASE_NOTES.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### 3.0.0-nagareyama-rc-009
2+
3+
* Improve lambda beta reduction
4+
* Fix #1962: Find entities by core assembly name
5+
* Fix #2283: FABLE_COMPILER_3 constant
6+
* Fix #2284: Inline import can absorb arguments
7+
* Fix #2288: Ignore --warnaserror from project references
8+
* Fix #2291: Default hashing for classes
9+
110
### 3.0.0-nagareyama-rc-008
211

312
* Fix FSharpType.IsTuple for array of tuples @kerams

src/Fable.Transforms/FSharp2Fable.Util.fs

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ type FsEnt(ent: FSharpEntity) =
130130
static member IsPublic (ent: FSharpEntity) =
131131
not ent.Accessibility.IsPrivate
132132

133-
static member QualifiedName (ent: FSharpEntity): string =
134-
let ent = Helpers.nonAbbreviatedDefinition ent
135-
match tryArrayFullName ent with
136-
| Some fullName -> fullName
137-
| None ->
138-
try ent.QualifiedName
139-
with _ -> ent.LogicalName
140-
141133
static member FullName (ent: FSharpEntity): string =
142134
let ent = Helpers.nonAbbreviatedDefinition ent
143135
match tryArrayFullName ent with
@@ -152,16 +144,16 @@ type FsEnt(ent: FSharpEntity) =
152144
| None -> ent.LogicalName
153145

154146
static member Ref (ent: FSharpEntity): Fable.EntityRef =
155-
let sourcePath =
156-
if Option.isSome ent.Assembly.FileName
157-
then None
158-
else Some(FsEnt.SourcePath ent)
159-
{ QualifiedName = FsEnt.QualifiedName ent
160-
SourcePath = sourcePath }
161-
162-
static member Ref (assemblyEntityQualifiedName: string): Fable.EntityRef =
163-
{ QualifiedName = assemblyEntityQualifiedName
164-
SourcePath = None }
147+
let path =
148+
match ent.Assembly.FileName with
149+
// When compiling with netcoreapp target, netstandard only contains redirects
150+
// Find the actual assembly name from the entity qualified name
151+
| Some asmPath when asmPath.EndsWith("netstandard.dll") ->
152+
ent.QualifiedName.Split(',').[1].Trim() |> Fable.CoreAssemblyName
153+
| Some asmPath -> Path.normalizePath asmPath |> Fable.AssemblyPath
154+
| None -> FsEnt.SourcePath ent |> Fable.SourcePath
155+
{ FullName = FsEnt.FullName ent
156+
Path = path }
165157

166158
interface Fable.Entity with
167159
member _.Ref = FsEnt.Ref ent
@@ -775,11 +767,11 @@ module TypeHelpers =
775767
dict ["bool`1", Choice1Of2 Fable.Boolean
776768
"byte`1", Choice1Of2 (Fable.Number UInt8)
777769
"string`1", Choice1Of2 Fable.String
778-
"uint64`1", Choice2Of2 Types.uint64
779-
"Guid`1", Choice2Of2 Types.guid
780-
"TimeSpan`1", Choice2Of2 Types.timespan
781-
"DateTime`1", Choice2Of2 Types.datetime
782-
"DateTimeOffset`1", Choice2Of2 Types.datetimeOffset]
770+
"uint64`1", Choice2Of2("System.Runtime", Types.uint64)
771+
"Guid`1", Choice2Of2("System.Runtime", Types.guid)
772+
"TimeSpan`1", Choice2Of2("System.Runtime", Types.timespan)
773+
"DateTime`1", Choice2Of2("System.Runtime", Types.datetime)
774+
"DateTimeOffset`1", Choice2Of2("System.Runtime", Types.datetimeOffset)]
783775

784776
let makeTypeFromDef ctxTypeArgs (genArgs: IList<FSharpType>) (tdef: FSharpEntity) =
785777
if tdef.IsArrayType then
@@ -808,7 +800,11 @@ module TypeHelpers =
808800
| Naming.StartsWith "FSharp.UMX." (DicContains fsharpUMX choice) ->
809801
match choice with
810802
| Choice1Of2 t -> t
811-
| Choice2Of2 qualifiedName -> Fable.DeclaredType(FsEnt.Ref qualifiedName, [])
803+
| Choice2Of2(dllName, fullName) ->
804+
let r: Fable.EntityRef =
805+
{ FullName = fullName
806+
Path = Fable.CoreAssemblyName dllName }
807+
Fable.DeclaredType(r, [])
812808
| _ ->
813809
// Special attributes
814810
tdef.Attributes |> tryPickAttribute [
@@ -857,7 +853,7 @@ module TypeHelpers =
857853
| _ -> ()
858854
}
859855

860-
let getArgTypes com (memb: FSharpMemberOrFunctionOrValue) =
856+
let getArgTypes _com (memb: FSharpMemberOrFunctionOrValue) =
861857
// FSharpParameters don't contain the `this` arg
862858
Seq.concat memb.CurriedParameterGroups
863859
// The F# compiler "untuples" the args in methods
@@ -878,7 +874,7 @@ module TypeHelpers =
878874
if t.HasTypeDefinition then Some t.TypeDefinition else None
879875
else None
880876

881-
let tryFindMember com (entity: Fable.Entity) genArgs compiledName isInstance (argTypes: Fable.Type list) =
877+
let tryFindMember _com (entity: Fable.Entity) genArgs compiledName isInstance (argTypes: Fable.Type list) =
882878
let argsEqual (args1: Fable.Type list) args1Length (args2: IList<IList<FSharpParameter>>) =
883879
let args2Length = args2 |> Seq.sumBy (fun g -> g.Count)
884880
if args1Length = args2Length then
@@ -898,7 +894,7 @@ module TypeHelpers =
898894
else false)
899895
| _ -> None
900896

901-
let fitsAnonRecordInInterface com (argExprs: Fable.Expr list) fieldNames (interface_: Fable.Entity) =
897+
let fitsAnonRecordInInterface _com (argExprs: Fable.Expr list) fieldNames (interface_: Fable.Entity) =
902898
match interface_ with
903899
| :? FsEnt as fsEnt ->
904900
let interface_ = fsEnt.FSharpEntity
@@ -931,7 +927,7 @@ module TypeHelpers =
931927

932928

933929

934-
let inline (|FableType|) com (ctx: Context) t = makeType ctx.GenericArgs t
930+
let inline (|FableType|) _com (ctx: Context) t = makeType ctx.GenericArgs t
935931

936932
module Identifiers =
937933
open Helpers
@@ -940,7 +936,7 @@ module Identifiers =
940936
let putIdentInScope (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue) (ident: Fable.Ident) value =
941937
{ ctx with Scope = (fsRef, ident, value)::ctx.Scope}
942938

943-
let makeIdentFrom (com: IFableCompiler) (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue): Fable.Ident =
939+
let makeIdentFrom (_com: IFableCompiler) (ctx: Context) (fsRef: FSharpMemberOrFunctionOrValue): Fable.Ident =
944940
let sanitizedName = (fsRef.CompiledName, Naming.NoMemberPart)
945941
||> Naming.sanitizeIdent (isUsedName ctx)
946942
ctx.UseNamesInDeclarationScope.Add(sanitizedName) |> ignore
@@ -1153,7 +1149,9 @@ module Util =
11531149
| _ -> false)
11541150

11551151
let isFromDllRef (ent: Fable.Entity) =
1156-
Option.isNone ent.Ref.SourcePath
1152+
match ent.Ref.Path with
1153+
| Fable.AssemblyPath _ | Fable.CoreAssemblyName _ -> true
1154+
| Fable.SourcePath _ -> false
11571155

11581156
let private isReplacementCandidatePrivate isFromDllRef (entFullName: string) =
11591157
if entFullName.StartsWith("System.") || entFullName.StartsWith("Microsoft.FSharp.") then isFromDllRef
@@ -1162,8 +1160,7 @@ module Util =
11621160
else entFullName.StartsWith("Fable.Core.")
11631161

11641162
let isReplacementCandidate (ent: Fable.Entity) =
1165-
let isFromDllRef = Option.isNone ent.Ref.SourcePath
1166-
isReplacementCandidatePrivate isFromDllRef ent.FullName
1163+
isReplacementCandidatePrivate (isFromDllRef ent) ent.FullName
11671164

11681165
let isReplacementCandidateFrom (ent: FSharpEntity) =
11691166
let isFromDllRef = Option.isSome ent.Assembly.FileName
@@ -1272,7 +1269,7 @@ module Util =
12721269
let entityName = defaultArg ent.TryFullName ""
12731270
entityName + "." + memberName + overloadHash
12741271

1275-
let callInstanceMember com r typ (callInfo: Fable.CallInfo)
1272+
let callInstanceMember _com r typ (callInfo: Fable.CallInfo)
12761273
(entity: FSharpEntity) (memb: FSharpMemberOrFunctionOrValue) =
12771274
let callInfo, callee =
12781275
match callInfo.ThisArg with
@@ -1455,7 +1452,7 @@ module Util =
14551452
if List.isEmpty args then importExpr
14561453
else makeCall r t info importExpr
14571454
| body ->
1458-
List.fold (fun body binding -> Fable.Let([binding], body)) body bindings
1455+
List.fold (fun body (ident, value) -> Fable.Let(ident, value, body)) body bindings
14591456

14601457
let (|Inlined|_|) (com: IFableCompiler) ctx r t genArgs callee info (memb: FSharpMemberOrFunctionOrValue) =
14611458
if isInline memb

0 commit comments

Comments
 (0)