Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions backend/src/Builtins/Builtins.Http.Client/Libs/HttpClient.fs
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,10 @@ let fns (config : Configuration) : List<BuiltInFn> =
FQFnName.fqPackage (
PackageRefs.Fn.Stdlib.HttpClient.request ()
),
[],
2,
"headers",
VT.list (VT.tuple VT.string VT.string []),
headersType,
Dval.toValueType notAPair,
notAPair
)
Expand Down Expand Up @@ -821,9 +822,10 @@ let fns (config : Configuration) : List<BuiltInFn> =
FQFnName.fqPackage (
PackageRefs.Fn.Stdlib.HttpClient.stream ()
),
[],
2,
"headers",
VT.list (VT.tuple VT.string VT.string []),
headersType,
Dval.toValueType notAPair,
notAPair
)
Expand Down
6 changes: 3 additions & 3 deletions backend/src/Builtins/Builtins.Pure/Libs/Float.fs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ let fns () : List<BuiltInFn> =
TypeReference.result
TFloat
(TCustomType(
{ originalName = []
resolved =
Ok(FQTypeName.fqPackage (PackageRefs.Type.Stdlib.floatParseError ())) },
NameResolution.ok (
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.floatParseError ())
),
[]
))
description =
Expand Down
8 changes: 3 additions & 5 deletions backend/src/Builtins/Builtins.Pure/Libs/Int128.fs
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,9 @@ let fns () : List<BuiltInFn> =
TypeReference.result
TInt128
(TCustomType(
{ originalName = []
resolved =
Ok(
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.int128ParseError ())
) },
NameResolution.ok (
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.int128ParseError ())
),
[]
))
description = "Returns the <type Int128> value of a <type String>"
Expand Down
6 changes: 5 additions & 1 deletion backend/src/Builtins/Builtins.Pure/Libs/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,9 @@ let parse
|> Ply.List.flatten
|> Ply.map (TypeChecker.DvalCreator.dict threadID VT.unknownTODO)

| TCustomType({ resolved = Ok typeName }, typeArgs), jsonValueKind ->
| TCustomType(({ resolved = Ok typeName } as nr), typeArgs), jsonValueKind ->
// The written reference name, so diagnostics don't show a hash-sibling.
let typeReferenceName = nr.originalName
uply {
let! typeArgsVT =
typeArgs |> Ply.List.mapSequentially (TypeReference.toVT types tst)
Expand Down Expand Up @@ -664,6 +666,7 @@ let parse
threadID
tst
typeName
typeReferenceName
typeArgsVT
caseName
fields
Expand Down Expand Up @@ -722,6 +725,7 @@ let parse
threadID
tst
typeName
typeReferenceName
typeArgsVT
fields
return record
Expand Down
56 changes: 52 additions & 4 deletions backend/src/Builtins/Builtins.Pure/Libs/NoModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,48 @@ module ValueType = LibExecution.ValueType
module RTE = RuntimeError


/// Removes diagnostic names from resolved custom type refs before equality.
/// Unresolved refs keep their name because it is the only identity they have.
let rec private normalizeTypeRefForEquality (t : TypeReference) : TypeReference =
let r = normalizeTypeRefForEquality
match t with
| TUnit
| TBool
| TInt8
| TUInt8
| TInt16
| TUInt16
| TInt32
| TUInt32
| TInt64
| TUInt64
| TInt128
| TUInt128
| TInt
| TFloat
| TChar
| TString
| TUuid
| TDateTime
| TBlob
| TVariable _ -> t
| TList inner -> TList(r inner)
| TDict inner -> TDict(r inner)
| TStream inner -> TStream(r inner)
| TDB inner -> TDB(r inner)
| TTuple(first, second, theRest) -> TTuple(r first, r second, List.map r theRest)
| TFn(args, ret) -> TFn(NEList.map r args, r ret)
| TCustomType(nr, typeArgs) ->
let nr =
match nr.resolved with
| Ok _ -> { nr with originalName = [] }
| Error _ -> nr
TCustomType(nr, List.map r typeArgs)

let private typeReferenceEquals (a : TypeReference) (b : TypeReference) : bool =
normalizeTypeRefForEquality a = normalizeTypeRefForEquality b


/// Structural equality. Walks two Dvals in parallel and returns
/// true iff every reachable leaf compares equal. Type errors
/// (callers passing structurally-incompatible Dvals) return false
Expand Down Expand Up @@ -107,11 +149,17 @@ let rec equals (a : Dval) (b : Dval) : bool =

| DApplicable a, DApplicable b ->
match a, b with
// CLEANUP exprId is a partial check — fully checking LambdaImpl
// equality needs lambda-internal-state work. Today this is
// "same-source-position lambdas compare equal."
// CLEANUP: lambda equality only checks source position. Include captures,
// applied args, and type bindings if lambda equality semantics are tightened.
| AppLambda a, AppLambda b -> a.exprId = b.exprId
| AppNamedFn a, AppNamedFn b -> a = b
| AppNamedFn a, AppNamedFn b ->
// Reference names are diagnostic-only, so they do not affect equality.
a.name = b.name
&& List.length a.typeArgs = List.length b.typeArgs
&& List.forall2 typeReferenceEquals a.typeArgs b.typeArgs
&& List.length a.argsSoFar = List.length b.argsSoFar
&& List.forall2 r a.argsSoFar b.argsSoFar
&& a.typeSymbolTable = b.typeSymbolTable
| _ -> false

| DDB a, DDB b -> a = b
Expand Down
8 changes: 3 additions & 5 deletions backend/src/Builtins/Builtins.Pure/Libs/UInt128.fs
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,9 @@ let fns () : List<BuiltInFn> =
TypeReference.result
TUInt128
(TCustomType(
{ originalName = []
resolved =
Ok(
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.uint128ParseError ())
) },
NameResolution.ok (
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.uint128ParseError ())
),
[]
))
description = "Returns the <type UInt128> value of a <type String>"
Expand Down
8 changes: 3 additions & 5 deletions backend/src/Builtins/Builtins.Pure/Libs/UInt64.fs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,9 @@ let fns () : List<BuiltInFn> =
TypeReference.result
TUInt64
(TCustomType(
{ originalName = []
resolved =
Ok(
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.uint64ParseError ())
) },
NameResolution.ok (
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.uint64ParseError ())
),
[]
))
description = "Returns the <type UInt64> value of a <type String>"
Expand Down
6 changes: 3 additions & 3 deletions backend/src/Builtins/Builtins.Pure/Libs/Uuid.fs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ let fns () : List<BuiltInFn> =
TypeReference.result
TUuid
(TCustomType(
{ originalName = []
resolved =
Ok(FQTypeName.fqPackage (PackageRefs.Type.Stdlib.uuidParseError ())) },
NameResolution.ok (
FQTypeName.fqPackage (PackageRefs.Type.Stdlib.uuidParseError ())
),
[]
))
description =
Expand Down
16 changes: 15 additions & 1 deletion backend/src/LibExecution/Execution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ let executeApplicable
}


let executeFunction
let executeReferencedFunction
(exeState : RT.ExecutionState)
(name : RT.FQFnName.FQFnName)
(referenceName : List<string>)
(typeArgs : List<RT.TypeReference>)
(args : NEList<RT.Dval>)
: Task<RT.ExecutionResult> =
Expand All @@ -191,6 +192,7 @@ let executeFunction
let fnInstr, fnReg, rc =
let namedFn : RT.ApplicableNamedFn =
{ name = name
referenceName = referenceName
typeSymbolTable = Map.empty
typeArgs = typeArgs
argsSoFar = [] }
Expand All @@ -214,6 +216,18 @@ let executeFunction
executeExpr exeState instrs


/// Execute a function by its resolved/content-addressed name only.
/// Use `executeReferencedFunction` when the caller has a user-written
/// reference name to preserve in runtime errors.
let executeFunction
(exeState : RT.ExecutionState)
(name : RT.FQFnName.FQFnName)
(typeArgs : List<RT.TypeReference>)
(args : NEList<RT.Dval>)
: Task<RT.ExecutionResult> =
executeReferencedFunction exeState name [] typeArgs args


let runtimeErrorToString
(state : RT.ExecutionState)
(rte : RT.RuntimeError.Error)
Expand Down
Loading