Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Syntax for creating ImmutableArrays #12859

Draft
wants to merge 48 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
77c2e30
Expand isArray to ConcreteSequence (list, array, immutableArray)
Mar 20, 2022
5236851
Get FSharp.Compiler.Service to build
Mar 20, 2022
ddb16da
fix rename
Mar 20, 2022
2113a4f
lex
Mar 20, 2022
74669ad
fix build
Mar 20, 2022
db9f9b5
fix naming
Mar 20, 2022
cbae870
consolidate naming
Mar 20, 2022
632dfb7
fix naming again
Mar 20, 2022
db599d8
implement one of the not implementeds
Mar 20, 2022
a7deb6a
fix build
Mar 20, 2022
4fb7721
mkBlockType
Mar 20, 2022
e94abcd
implement
Mar 20, 2022
c80be31
implement
Mar 20, 2022
ced13f7
picle TOp.Block and improve the TypedTreePickle structure
Mar 20, 2022
b476ff6
FSStrings
Mar 20, 2022
dbedee8
run tests - autogenerated file?
Mar 20, 2022
9c250d7
tidy
Mar 21, 2022
8717c40
replace expected with actual
Mar 21, 2022
4b230dc
implement
Mar 21, 2022
2c3f103
collector
Mar 21, 2022
8c41bc5
fix build
Mar 21, 2022
1418ec4
tidy
Mar 21, 2022
2d9bbb6
add a newline
Mar 21, 2022
0948c7c
fix typo
Mar 21, 2022
a2b05fa
more additions to match array tokens
Mar 22, 2022
fbe107f
missed
Mar 22, 2022
b7a2380
fix text file
Mar 22, 2022
298247b
typo
Mar 24, 2022
9cfbeb4
typos
Mar 24, 2022
e000786
grammar typo
Mar 24, 2022
4df899b
merge
May 17, 2022
8705031
fix merge
May 17, 2022
6dccd14
fix merge
May 17, 2022
afabd07
merge
May 2, 2023
9c90047
fix merge
May 2, 2023
93dac68
fix a merge issue
May 2, 2023
7624cef
merge issues
May 2, 2023
66524f3
save file before committing??
May 2, 2023
71011a7
fix merge
May 2, 2023
5d7faef
Revert "fix merge"
May 2, 2023
a49e40d
parsUnmatchedBracketColon
May 3, 2023
c5ca8bb
fix
May 3, 2023
990816f
spacing
May 3, 2023
8938576
add TOpEnum
May 3, 2023
7b79e26
fix merge error
May 3, 2023
e12309d
attempt to fix build errors reported by @nojaf
May 3, 2023
5d4a2d1
fix merge
May 3, 2023
7acde1b
work done in amplifying F# session
May 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Compiler/Checking/CheckExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5889,7 +5889,19 @@ and TcExprArrayOrList (cenv: cenv) overallTy env tpenv (cType: CollectionType, a
| CollectionType.List ->
List.foldBack (mkCons g argTy) argsR (mkNil g m argTy)
| CollectionType.ImmutableArray ->
Expr.Op (TOp.Block, [argTy], argsR, m)
//// TODO: the idea is to use code from builder called in LowerComputedListOrArraySeqExpr. Need to find tcVal to check whether the approach works.
//let infoReader = InfoReader(g, cenv.amap)
//let collectorTy = g.mk_BlockCollector_ty argTy
//let name = "AddMany"
//let collVal, collExpr = mkMutableCompGenLocal m "@collector" collectorTy
//let listCollectorTy = tyOfExpr g collExpr
//let addMethod =
// match GetIntrinsicMethInfosOfType infoReader (Some name) AccessibleFromSomewhere AllowMultiIntfInstantiations.Yes IgnoreOverrides m listCollectorTy with
// | [x] -> x
// | _ -> error(InternalError("no " + name + " method found on Collector", m))
//let expr, _ = BuildMethodCall tcVal g infoReader.amap DefinitelyMutates m false addMethod NormalValUse [] [collExpr] args None
//expr
Expr.Op (TOp.Block, [argTy], argsR, m) // This code goes down a path that is currently not handled
expr, tpenv
)

Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3001,6 +3001,9 @@ and GenExprAux (cenv: cenv) (cgbuf: CodeGenBuffer) eenv expr (sequel: sequel) =
| TOp.LValueOp (LByrefSet, v), [ e ], [] -> GenSetByref cenv cgbuf eenv (v, e, m) sequel
| TOp.LValueOp (LAddrOf _, v), [], [] -> GenGetValAddr cenv cgbuf eenv (v, m) sequel
| TOp.Array, elems, [ elemTy ] -> GenNewArray cenv cgbuf eenv (elems, elemTy, m) sequel
| TOp.Block, elems, [ elemTy ] ->
// This codepath is currently reached with non-computation-expression arrays and not handled
failwith $"entering | TOp.Block, {elems}, [ {elemTy} ] ->"
| TOp.Bytes bytes, [], [] ->
if cenv.options.emitConstantArraysUsingStaticDataBlobs then
GenConstArray cenv cgbuf eenv g.ilg.typ_Byte bytes (fun buf b -> buf.EmitByte b)
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -4506,6 +4506,9 @@ atomicExpr:
| LBRACK listExprElements RBRACK
{ $2 (lhs parseState), false }

| immarrayExpr
{ $1, false }

| LBRACK listExprElements recover
{ reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnmatchedBracket())
exprFromParseError ($2 (rhs2 parseState 1 2)), false }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
<Compile Include="ErrorMessages\InterfaceImplInAugmentationsTests.fs" />
<Compile Include="Language\IndexerSetterParamArray.fs" />
<Compile Include="Language\MultiDimensionalArrayTests.fs" />
<Compile Include="Language\ImmArrayTests.fs" />
<Compile Include="Language\RegressionTests.fs" />
<Compile Include="Language\AttributeCheckingTests.fs" />
<Compile Include="Language\ObsoleteAttributeCheckingTests.fs" />
Expand All @@ -187,6 +188,9 @@
<Compile Include="Language\PrintfFormatTests.fs" />
<Compile Include="Language\InterfaceTests.fs" />
<Compile Include="Language\CopyAndUpdateTests.fs" />
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)TestSource\%(Filename)%(Extension)</Link>
</None>
<Compile Include="ConstraintSolver\PrimitiveConstraints.fs" />
<Compile Include="ConstraintSolver\MemberConstraints.fs" />
<Compile Include="Interop\DeeplyNestedCSharpClasses.fs" />
Expand Down Expand Up @@ -248,11 +252,7 @@
<Compile Include="FSharpChecker\FindReferences.fs" />
</ItemGroup>

<ItemGroup>
<None Include="**\*.cs;**\*.fs;**\*.fsx;**\*.fsi" Exclude="@(Compile)">
<Link>%(RelativeDir)TestSource\%(Filename)%(Extension)</Link>
</None>
</ItemGroup>
<ItemGroup />

<ItemGroup>
<None Include="**\*.bsl">
Expand Down
27 changes: 27 additions & 0 deletions tests/FSharp.Compiler.ComponentTests/Language/ImmArrayTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

module FSharp.Compiler.ComponentTests.Language.ImmArrayTests

open Xunit
open FSharp.Test.Compiler

[<Fact>]
let ``Check creation of a single-element immarray``() =
FSharp """
module ImmarrayTest

let x = [: 42 :]
"""
|> compile
|> shouldSucceed

[<Fact>]
let ``Check creation of an immarray with yields``() =
FSharp """
module ImmarrayTest

let x = [: for i = 0 to 100 do yield 42 :]
let y = x |> Seq.sum
"""
|> compile
|> shouldSucceed