Skip to content

Commit

Permalink
Fixed merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Jan 15, 2025
1 parent 4a9a221 commit cbb34c1
Show file tree
Hide file tree
Showing 37 changed files with 592 additions and 306 deletions.
4 changes: 2 additions & 2 deletions buildtools/buildtools.targets
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
BeforeTargets="CoreCompile">

<PropertyGroup>
<FsLexPath Condition="'$(FsLexPath)' == ''">$(ArtifactsDir)\bin\fslex\Release\net8.0\fslex.dll</FsLexPath>
<FsLexPath Condition="'$(FsLexPath)' == ''">$(ArtifactsDir)\bin\fslex\Release\net9.0\linux-x64\fslex.dll</FsLexPath>
</PropertyGroup>

<!-- Create the output directory -->
Expand All @@ -44,7 +44,7 @@
BeforeTargets="CoreCompile">

<PropertyGroup>
<FsYaccPath Condition="'$(FsYaccPath)' == ''">$(ArtifactsDir)\bin\fsyacc\Release\net8.0\fsyacc.dll</FsYaccPath>
<FsYaccPath Condition="'$(FsYaccPath)' == ''">$(ArtifactsDir)\bin\fsyacc\Release\net9.0\linux-x64\fsyacc.dll</FsYaccPath>
</PropertyGroup>

<!-- Create the output directory -->
Expand Down
4 changes: 3 additions & 1 deletion fcs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
cd $(dirname $0)/..

# build fslex/fsyacc tools
dotnet build -c Release buildtools
dotnet build -c Release buildtools/fslex
dotnet build -c Release buildtools/fsyacc

# build FSharp.Compiler.Service (to make sure it's not broken)
dotnet build -c Release src/Compiler

Expand Down
45 changes: 27 additions & 18 deletions fcs/fcs-fable/FSStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ let resources =
( "ConstraintSolverMissingConstraint",
"A type parameter is missing a constraint '{0}'"
);
( "ConstraintSolverNullnessWarningEquivWithTypes",
"Nullness warning: A non-nullable '{0}' was expected but this expression is nullable. Consider either changing the target to also be nullable, or use pattern matching to safely handle the null case of this expression."
);
( "ConstraintSolverNullnessWarningWithTypes",
"Nullness warning: The types '{0}' and '{1}' do not have compatible nullability."
);
( "ConstraintSolverNullnessWarningWithType",
"Nullness warning: The type '{0}' does not support 'null'."
);
( "ConstraintSolverNullnessWarning",
"Nullness warning: {0}."
);
( "ConstraintSolverTypesNotInEqualityRelation1",
"The unit of measure '{0}' does not match the unit of measure '{1}'"
);
Expand Down Expand Up @@ -69,7 +81,7 @@ let resources =
"Duplicate definition of {0} '{1}'"
);
( "NameClash2",
"The {0} '{1}' can not be defined because the name '{2}' clashes with the {3} '{4}' in this type or module"
"The {0} '{1}' cannot be defined because the name '{2}' clashes with the {3} '{4}' in this type or module"
);
( "Duplicate1",
"Two members called '{0}' have the same signature"
Expand Down Expand Up @@ -105,7 +117,7 @@ let resources =
"A coercion from the value type \n {0} \nto the type \n {1} \nwill involve boxing. Consider using 'box' instead"
);
( "TypeIsImplicitlyAbstract",
"This type is 'abstract' since some abstract members have not been given an implementation. If this is intentional then add the '[<AbstractClass>]' attribute to your type."
"Non-abstract classes cannot contain abstract members. Either provide a default member implementation or add the '[<AbstractClass>]' attribute to your type."
);
( "NonRigidTypar1",
"This construct causes code to be less generic than indicated by its type annotations. The type variable implied by the use of a '#', '_' or other type annotation at or near '{0}' has been constrained to be type '{1}'."
Expand Down Expand Up @@ -299,6 +311,9 @@ let resources =
( "Parser.TOKEN.BAR.RBRACE",
"symbol '|}'"
);
( "Parser.TOKEN.BAR_JUST_BEFORE_NULL",
"symbol '|' (directly before 'null')"
);
( "Parser.TOKEN.GREATER.RBRACE",
"symbol '>}'"
);
Expand Down Expand Up @@ -914,20 +929,11 @@ let resources =
( "MissingFields",
"The following fields require values: {0}"
);
( "ValueRestriction1",
"Value restriction. The value '{0}' has generic type\n {1} \nEither make the arguments to '{2}' explicit or, if you do not intend for it to be generic, add a type annotation."
( "ValueRestrictionFunction",
"""Value restriction: The value '{0}' has an inferred generic function type\n {1}\nHowever, values cannot have generic type variables like '_a in "let f: '_a". You should define '{2}' as a function instead by doing one of the following:\n- Add an explicit parameter that is applied instead of using a partial application "let f param"\n- Add a unit parameter like "let f()"\n- Write explicit type parameters like "let f<'a>"\nor if you do not intend for it to be generic, either:\n- Add an explicit type annotation like "let f : obj -> obj"\n- Apply arguments of non-generic types to the function value in later code for type inference like "do f()".\nThis error is because a let binding without parameters defines a value, not a function. Values cannot be generic because reading a value is assumed to result in the same everywhere but generic type parameters may invalidate this assumption by enabling type-dependent results."""
);
( "ValueRestriction2",
"Value restriction. The value '{0}' has generic type\n {1} \nEither make '{2}' into a function with explicit arguments or, if you do not intend for it to be generic, add a type annotation."
);
( "ValueRestriction3",
"Value restriction. This member has been inferred to have generic type\n {0} \nConstructors and property getters/setters cannot be more generic than the enclosing type. Add a type annotation to indicate the exact types involved."
);
( "ValueRestriction4",
"Value restriction. The value '{0}' has been inferred to have generic type\n {1} \nEither make the arguments to '{2}' explicit or, if you do not intend for it to be generic, add a type annotation."
);
( "ValueRestriction5",
"Value restriction. The value '{0}' has been inferred to have generic type\n {1} \nEither define '{2}' as a simple data term, make it a function with explicit arguments or, if you do not intend for it to be generic, add a type annotation."
( "ValueRestriction",
"""Value restriction: The value '{0}' has an inferred generic type\n {1}\nHowever, values cannot have generic type variables like '_a in "let x: '_a". You can do one of the following:\n- Define it as a simple data term like an integer literal, a string literal or a union case like "let x = 1"\n- Add an explicit type annotation like "let x : int"\n- Use the value as a non-generic type in later code for type inference like "do x"\nor if you still want type-dependent results, you can define '{2}' as a function instead by doing either:\n- Add a unit parameter like "let x()"\n- Write explicit type parameters like "let x<'a>".\nThis error is because a let binding without parameters defines a value, not a function. Values cannot be generic because reading a value is assumed to result in the same everywhere but generic type parameters may invalidate this assumption by enabling type-dependent results."""
);
( "RecoverableParseError",
"syntax error"
Expand All @@ -945,7 +951,7 @@ let resources =
"Override implementations should be given as part of the initial declaration of a type."
);
( "IntfImplInIntrinsicAugmentation",
"Interface implementations should normally be given on the initial declaration of a type. Interface implementations in augmentations may lead to accessing static bindings before they are initialized, though only if the interface implementation is invoked during initialization of the static data, and in turn access the static data. You may remove this warning using #nowarn \"69\" if you have checked this is not the case."
"Interface implementations should normally be given on the initial declaration of a type. Interface implementations in augmentations may lead to accessing static bindings before they are initialized, though only if the interface implementation is invoked during initialization of the static data, and in turn access the static data. You may remove this warning using '#nowarn \"69\"' if you have checked this is not the case."
);
( "IntfImplInExtrinsicAugmentation",
"Interface implementations should be given on the initial declaration of a type."
Expand All @@ -957,10 +963,10 @@ let resources =
"The type referenced through '{0}' is defined in an assembly that is not referenced. You must add a reference to assembly '{1}'."
);
( "HashIncludeNotAllowedInNonScript",
"#I directives may only occur in F# script files (extensions .fsx or .fsscript). Either move this code to a script file, add a '-I' compiler option for this reference or delimit the directive with delimit it with '#if INTERACTIVE'/'#endif'."
"#I directives may only be used in F# script files (extensions .fsx or .fsscript). Either move this code to a script file, add a '-I' compiler option for this reference or delimit the directive with delimit it with '#if INTERACTIVE'/'#endif'."
);
( "HashReferenceNotAllowedInNonScript",
"#r directives may only occur in F# script files (extensions .fsx or .fsscript). Either move this code to a script file or replace this reference with the '-r' compiler option. If this directive is being executed as user input, you may delimit it with '#if INTERACTIVE'/'#endif'."
"#r directives may only be used in F# script files (extensions .fsx or .fsscript). Either move this code to a script file or replace this reference with the '-r' compiler option. If this directive is being executed as user input, you may delimit it with '#if INTERACTIVE'/'#endif'."
);
( "HashDirectiveNotAllowedInNonScript",
"This directive may only be used in F# script files (extensions .fsx or .fsscript). Either remove the directive, move this code to a script file or delimit the directive with '#if INTERACTIVE'/'#endif'."
Expand Down Expand Up @@ -1007,6 +1013,9 @@ let resources =
( "ArgumentsInSigAndImplMismatch",
"The argument names in the signature '{0}' and implementation '{1}' do not match. The argument name from the signature file will be used. This may cause problems when debugging or profiling."
);
( "DefinitionsInSigAndImplNotCompatibleAbbreviationsDiffer",
"The {0} definitions for type '{1}' in the signature and implementation are not compatible because the abbreviations differ:\n {2}\nversus\n {3}"
);
( "Parser.TOKEN.WHILE.BANG",
"keyword 'while!'"
);
Expand Down
9 changes: 8 additions & 1 deletion fcs/fcs-fable/SR.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
namespace FSharp.Compiler

module SR =
let GetString(name: string) =
let GetString (name: string) =
match SR.Resources.resources.TryGetValue(name) with
| true, value -> value
| _ -> "Missing FSStrings error message for: " + name

module FSComp =
module SR =
let GetTextOpt (name: string) =
match SR.Resources.resources.TryGetValue(name) with
| true, value -> Some value
| _ -> None

module DiagnosticMessage =
type ResourceString<'T>(sfmt: string, fmt: string) =
member x.Format =
Expand Down
83 changes: 83 additions & 0 deletions fcs/fcs-fable/System.Collections.Concurrent.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//------------------------------------------------------------------------
// shims for things not yet implemented in Fable
//------------------------------------------------------------------------

namespace System.Collections.Concurrent

open System.Collections.Generic

// not thread safe, just a ResizeArray // TODO: threaded implementation
type ConcurrentStack<'T>() =
let xs = ResizeArray<'T>()

member _.Push (item: 'T) = xs.Add(item)
member _.PushRange (items: 'T[]) = xs.AddRange(items)
member _.Clear () = xs.Clear()
member _.ToArray () = xs.ToArray()

interface IEnumerable<'T> with
member _.GetEnumerator() =
xs.GetEnumerator()

interface System.Collections.IEnumerable with
member _.GetEnumerator() =
(xs.GetEnumerator() :> System.Collections.IEnumerator)

// not thread safe, just a Dictionary // TODO: threaded implementation
[<AllowNullLiteral>]
type ConcurrentDictionary<'K, 'V>(comparer: IEqualityComparer<'K>) =
inherit Dictionary<'K, 'V>(comparer)

new () =
ConcurrentDictionary<'K, 'V>(EqualityComparer.Default)
new (_concurrencyLevel: int, _capacity: int) =
ConcurrentDictionary<'K, 'V>()
new (_concurrencyLevel: int, comparer: IEqualityComparer<'K>) =
ConcurrentDictionary<'K, 'V>(comparer)
new (_concurrencyLevel: int, _capacity: int, comparer: IEqualityComparer<'K>) =
ConcurrentDictionary<'K, 'V>(comparer)

member x.TryAdd (key: 'K, value: 'V): bool =
if x.ContainsKey(key)
then false
else x.Add(key, value); true

member x.TryRemove (key: 'K): bool * 'V =
match x.TryGetValue(key) with
| true, v -> (x.Remove(key), v)
| _ as res -> res

member x.GetOrAdd (key: 'K, value: 'V): 'V =
match x.TryGetValue(key) with
| true, v -> v
| _ -> let v = value in x.Add(key, v); v

member x.GetOrAdd (key: 'K, valueFactory: System.Func<'K, 'V>): 'V =
match x.TryGetValue(key) with
| true, v -> v
| _ -> let v = valueFactory.Invoke(key) in x.Add(key, v); v

// member x.GetOrAdd<'Arg> (key: 'K, valueFactory: 'K * 'Arg -> 'V, arg: 'Arg): 'V =
// match x.TryGetValue(key) with
// | true, v -> v
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v

member x.TryUpdate (key: 'K, value: 'V, comparisonValue: 'V): bool =
match x.TryGetValue(key) with
| true, v when Unchecked.equals v comparisonValue -> x[key] <- value; true
| _ -> false

member x.AddOrUpdate (key: 'K, value: 'V, updateFactory: System.Func<'K, 'V, 'V>): 'V =
match x.TryGetValue(key) with
| true, v -> let v = updateFactory.Invoke(key, v) in x[key] <- v; v
| _ -> let v = value in x.Add(key, v); v

// member x.AddOrUpdate (key: 'K, valueFactory: 'K -> 'V, updateFactory: 'K * 'V -> 'V): 'V =
// match x.TryGetValue(key) with
// | true, v -> let v = updateFactory(key, v) in x[key] <- v; v
// | _ -> let v = valueFactory(key) in x.Add(key, v); v

// member x.AddOrUpdate (key: 'K, valueFactory: 'K * 'Arg -> 'V, updateFactory: 'K * 'Arg * 'V -> 'V, arg: 'Arg): 'V =
// match x.TryGetValue(key) with
// | true, v -> let v = updateFactory(key, arg, v) in x[key] <- v; v
// | _ -> let v = valueFactory(key, arg) in x.Add(key, v); v
121 changes: 121 additions & 0 deletions fcs/fcs-fable/System.Collections.Generic.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//------------------------------------------------------------------------
// shims for things not yet implemented in Fable
//------------------------------------------------------------------------

namespace System.Collections.Generic

[<AllowNullLiteral>]
type LinkedListNode<'T>(value: 'T) =
member val Value = value with get, set
member val Previous: LinkedListNode<'T> = null with get, set
member val Next: LinkedListNode<'T> = null with get, set

type LinkedList<'T>() =
let mutable head: LinkedListNode<'T> = null
let mutable tail: LinkedListNode<'T> = null

// Get the first node in the list
member _.First = head

// Get the last node in the list
member _.Last = tail

// Get the number of nodes in the list
member _.Count =
let rec loop (currentNode: LinkedListNode<'T>) count =
if currentNode = null then count
else loop currentNode.Next (count + 1)
loop head 0

// Clear the list
member _.Clear() =
head <- null
tail <- null

// Add a new node to the end of the list
member _.AddLast(value: 'T) =
let newNode = LinkedListNode(value)
if tail = null then
head <- newNode
tail <- newNode
else
tail.Next <- newNode
newNode.Previous <- tail
tail <- newNode
newNode

// Add a node to the end of the list
member _.AddLast(node: LinkedListNode<'T>) =
if tail = null then
node.Next <- null
node.Previous <- null
head <- node
tail <- node
else
tail.Next <- node
node.Next <- null
node.Previous <- tail
tail <- node

// Add a new node to the beginning of the list
member _.AddFirst(value: 'T) =
let newNode = LinkedListNode(value)
if head = null then
head <- newNode
tail <- newNode
else
head.Previous <- newNode
newNode.Next <- head
head <- newNode
newNode

// Add a node to the beginning of the list
member _.AddFirst(node: LinkedListNode<'T>) =
if head = null then
node.Next <- null
node.Previous <- null
head <- node
tail <- node
else
head.Previous <- node
node.Next <- head
node.Previous <- null
head <- node

// Remove a node from the list
member _.Remove(node: LinkedListNode<'T>) =
match node.Previous, node.Next with
| null, null ->
head <- null
tail <- null
| null, nextNode ->
nextNode.Previous <- null
head <- nextNode
| prevNode, null ->
prevNode.Next <- null
tail <- prevNode
| prevNode, nextNode ->
prevNode.Next <- nextNode
nextNode.Previous <- prevNode

// Find a node by value
member _.Find(value: 'T) =
let rec loop (currentNode: LinkedListNode<'T>) =
if currentNode = null then null
elif Unchecked.equals currentNode.Value value then currentNode
else loop currentNode.Next
loop head

// Implement IEnumerable interface
interface System.Collections.Generic.IEnumerable<'T> with
member _.GetEnumerator() =
let rec loop (currentNode: LinkedListNode<'T>) =
seq {
if currentNode <> null then
yield currentNode.Value
yield! loop currentNode.Next
}
(loop head).GetEnumerator()

member this.GetEnumerator() : System.Collections.IEnumerator =
(this :> System.Collections.Generic.IEnumerable<'T>).GetEnumerator() :> System.Collections.IEnumerator
Loading

0 comments on commit cbb34c1

Please sign in to comment.