Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b40740a
Broken code for trywith in seq
T-Gro Dec 27, 2022
25173a2
Merge branch 'main' into try-with-in-seq
T-Gro Jan 2, 2023
3fd3ccb
try/with for sequence expressions - failing, but building
T-Gro Jan 3, 2023
8f45864
Adding more tests
T-Gro Jan 3, 2023
2cff81f
Failing test added - error at enumeration time not being caught!
T-Gro Jan 3, 2023
e3dc32d
More tailored failing tests added
T-Gro Jan 3, 2023
8169555
pushing 'with' clause into the generated state machine for chained ex…
T-Gro Jan 3, 2023
e132656
More test cases - recursion from with, inner try-finally inside of with
T-Gro Jan 4, 2023
0b1a854
combinator for trywith added, not yet hooked up
T-Gro Jan 4, 2023
e40e6f8
Calling combinator from seqexpression translation (failing now, incor…
T-Gro Jan 4, 2023
db5ada6
Fixing expressions to become lambdas
T-Gro Jan 4, 2023
1f493f5
Demonstrate slow recursion case
T-Gro Jan 4, 2023
ee7e593
Removing old version of the code
T-Gro Jan 4, 2023
a44cfbe
Merge branch 'main' into try-with-in-seq
T-Gro Jan 5, 2023
3dfbb1a
fantomas
T-Gro Jan 5, 2023
8c25b20
Merge branch 'main' into try-with-in-seq
T-Gro Jan 30, 2023
221e1f8
Try-with IL baseline test for .tail instruction present
T-Gro Jan 30, 2023
7b85ff7
Language switch for try/with in seq{}
T-Gro Jan 30, 2023
8d498ac
Typecheck tests to use preview langversion
T-Gro Jan 30, 2023
331d11f
Fsharp.Core baseline updated
T-Gro Jan 31, 2023
625e91c
Code styling
T-Gro Feb 1, 2023
f56bf57
Merge branch 'main' into try-with-in-seq
T-Gro Feb 1, 2023
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
41 changes: 39 additions & 2 deletions src/Compiler/Checking/CheckComputationExpressions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,13 @@ let mkSeqFinally (cenv: cenv) env m genTy e1 e2 =
let e1 = mkCoerceIfNeeded cenv.g (mkSeqTy cenv.g genResultTy) (tyOfExpr cenv.g e1) e1
mkCallSeqFinally cenv.g m genResultTy e1 e2

let mkSeqTryWith (cenv: cenv) env m genTy origSeq exnFilter exnHandler =
let g = cenv.g
let genResultTy = NewInferenceType g
UnifyTypes cenv env m genTy (mkSeqTy cenv.g genResultTy)
let origSeq = mkCoerceIfNeeded cenv.g (mkSeqTy cenv.g genResultTy) (tyOfExpr cenv.g origSeq) origSeq
mkCallSeqTryWith cenv.g m genResultTy origSeq exnFilter exnHandler

let mkSeqExprMatchClauses (pat, vspecs) innerExpr =
[MatchClause(pat, None, TTarget(vspecs, innerExpr, None), pat.Range) ]

Expand Down Expand Up @@ -2079,8 +2086,38 @@ let TcSequenceExpression (cenv: cenv) env tpenv comp (overallTy: OverallTy) m =

Some(mkLet spMatch inputExprMark matchv inputExpr matchExpr, tpenv)

| SynExpr.TryWith (trivia={ TryToWithRange = mTryToWith }) ->
error(Error(FSComp.SR.tcTryIllegalInSequenceExpression(), mTryToWith))
| SynExpr.TryWith (innerTry,withList,mTryToWith,_spTry,_spWith,trivia) ->
if not(g.langVersion.SupportsFeature(LanguageFeature.TryWithInSeqExpression)) then
error(Error(FSComp.SR.tcTryIllegalInSequenceExpression(), mTryToWith))

let env = { env with eIsControlFlow = true }
let tryExpr, tpenv =
let inner,tpenv = tcSequenceExprBody env genOuterTy tpenv innerTry
mkSeqDelayedExpr mTryToWith inner, tpenv

// Compile the pattern twice, once as a filter with all succeeding targets returning "1", and once as a proper catch block.
let clauses, tpenv =
(tpenv, withList) ||> List.mapFold (fun tpenv (SynMatchClause(pat, cond, innerComp, m, sp, _)) ->
let patR, condR, vspecs, envinner, tpenv = TcMatchPattern cenv g.exn_ty env tpenv pat cond
let envinner =
match sp with
| DebugPointAtTarget.Yes -> { envinner with eIsControlFlow = true }
| DebugPointAtTarget.No -> envinner
let matchBody, tpenv = tcSequenceExprBody envinner genOuterTy tpenv innerComp
let handlerClause = MatchClause(patR, condR, TTarget(vspecs, matchBody, None), patR.Range)
let filterClause = MatchClause(patR, condR, TTarget([], Expr.Const(Const.Int32 1,m,g.int_ty), None), patR.Range)
(handlerClause,filterClause), tpenv)

let handlers, filterClauses = List.unzip clauses
let withRange = trivia.WithToEndRange
let v1, filterExpr = CompilePatternForMatchClauses cenv env withRange withRange true FailFilter None g.exn_ty g.int_ty filterClauses
let v2, handlerExpr = CompilePatternForMatchClauses cenv env withRange withRange true FailFilter None g.exn_ty genOuterTy handlers

let filterLambda = mkLambda filterExpr.Range v1 (filterExpr, genOuterTy)
let handlerLambda = mkLambda handlerExpr.Range v2 (handlerExpr, genOuterTy)

let combinatorExpr = mkSeqTryWith cenv env mTryToWith genOuterTy tryExpr filterLambda handlerLambda
Some (combinatorExpr,tpenv)

| SynExpr.YieldOrReturnFrom ((isYield, _), synYieldExpr, m) ->
let env = { env with eIsControlFlow = false }
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1561,6 +1561,7 @@ featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members
featureWarningWhenInliningMethodImplNoInlineMarkedFunction,"Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined."
featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals"
featureErrorReportingOnStaticClasses,"Error reporting on static classes"
featureTryWithInSeqExpressions,"Support for try-with in sequence expressions"
featureWarningWhenCopyAndUpdateRecordChangesAllFields,"Raises warnings when an copy-and-update record expression changes all fields of a record."
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/Facilities/LanguageFeatures.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type LanguageFeature =
| EscapeDotnetFormattableStrings
| ArithmeticInLiterals
| ErrorReportingOnStaticClasses
| TryWithInSeqExpression
| WarningWhenCopyAndUpdateRecordChangesAllFields

/// LanguageVersion management
Expand Down Expand Up @@ -139,6 +140,7 @@ type LanguageVersion(versionText) =
LanguageFeature.EscapeDotnetFormattableStrings, previewVersion
LanguageFeature.ArithmeticInLiterals, previewVersion
LanguageFeature.ErrorReportingOnStaticClasses, previewVersion
LanguageFeature.TryWithInSeqExpression, previewVersion
LanguageFeature.WarningWhenCopyAndUpdateRecordChangesAllFields, previewVersion

]
Expand Down Expand Up @@ -254,6 +256,7 @@ type LanguageVersion(versionText) =
| LanguageFeature.EscapeDotnetFormattableStrings -> FSComp.SR.featureEscapeBracesInFormattableString ()
| LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals ()
| LanguageFeature.ErrorReportingOnStaticClasses -> FSComp.SR.featureErrorReportingOnStaticClasses ()
| LanguageFeature.TryWithInSeqExpression -> FSComp.SR.featureTryWithInSeqExpressions ()
| LanguageFeature.WarningWhenCopyAndUpdateRecordChangesAllFields -> FSComp.SR.featureWarningWhenCopyAndUpdateRecordChangesAllFields ()

/// Get a version string associated with the given feature.
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/Facilities/LanguageFeatures.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type LanguageFeature =
| EscapeDotnetFormattableStrings
| ArithmeticInLiterals
| ErrorReportingOnStaticClasses
| TryWithInSeqExpression
| WarningWhenCopyAndUpdateRecordChangesAllFields

/// LanguageVersion management
Expand Down
6 changes: 4 additions & 2 deletions src/Compiler/TypedTree/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ type TcGlobals(
let v_seq_using_info = makeIntrinsicValRef(fslib_MFRuntimeHelpers_nleref, "EnumerateUsing" , None , None , [vara;varb;varc], ([[varaTy];[(varaTy --> varbTy)]], mkSeqTy varcTy))
let v_seq_generated_info = makeIntrinsicValRef(fslib_MFRuntimeHelpers_nleref, "EnumerateWhile" , None , None , [varb], ([[v_unit_ty --> v_bool_ty]; [mkSeqTy varbTy]], mkSeqTy varbTy))
let v_seq_finally_info = makeIntrinsicValRef(fslib_MFRuntimeHelpers_nleref, "EnumerateThenFinally" , None , None , [varb], ([[mkSeqTy varbTy]; [v_unit_ty --> v_unit_ty]], mkSeqTy varbTy))
let v_seq_trywith_info = makeIntrinsicValRef(fslib_MFRuntimeHelpers_nleref, "EnumerateTryWith" , None , None , [varb], ([[mkSeqTy varbTy]; [mkNonGenericTy v_exn_tcr --> v_int32_ty]; [mkNonGenericTy v_exn_tcr --> mkSeqTy varbTy]], mkSeqTy varbTy))
let v_seq_of_functions_info = makeIntrinsicValRef(fslib_MFRuntimeHelpers_nleref, "EnumerateFromFunctions" , None , None , [vara;varb], ([[v_unit_ty --> varaTy]; [varaTy --> v_bool_ty]; [varaTy --> varbTy]], mkSeqTy varbTy))
let v_create_event_info = makeIntrinsicValRef(fslib_MFRuntimeHelpers_nleref, "CreateEvent" , None , None , [vara;varb], ([[varaTy --> v_unit_ty]; [varaTy --> v_unit_ty]; [(v_obj_ty --> (varbTy --> v_unit_ty)) --> varaTy]], mkIEvent2Ty varaTy varbTy))
let v_cgh__useResumableCode_info = makeIntrinsicValRef(fslib_MFStateMachineHelpers_nleref, "__useResumableCode" , None , None , [vara], ([[]], v_bool_ty))
Expand Down Expand Up @@ -1624,15 +1625,16 @@ type TcGlobals(
member val query_select_vref = ValRefForIntrinsic v_query_select_value_info
member val query_where_vref = ValRefForIntrinsic v_query_where_value_info
member val query_zero_vref = ValRefForIntrinsic v_query_zero_value_info
member val seq_to_list_vref = ValRefForIntrinsic v_seq_to_list_info
member val seq_to_array_vref = ValRefForIntrinsic v_seq_to_array_info
member val seq_to_list_vref = ValRefForIntrinsic v_seq_to_list_info
member val seq_to_array_vref = ValRefForIntrinsic v_seq_to_array_info

member _.seq_collect_info = v_seq_collect_info
member _.seq_using_info = v_seq_using_info
member _.seq_delay_info = v_seq_delay_info
member _.seq_append_info = v_seq_append_info
member _.seq_generated_info = v_seq_generated_info
member _.seq_finally_info = v_seq_finally_info
member _.seq_trywith_info = v_seq_trywith_info
member _.seq_of_functions_info = v_seq_of_functions_info
member _.seq_map_info = v_seq_map_info
member _.seq_singleton_info = v_seq_singleton_info
Expand Down
3 changes: 3 additions & 0 deletions src/Compiler/TypedTree/TypedTreeOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7749,6 +7749,9 @@ let mkCallSeqGenerated g m elemTy arg1 arg2 =

let mkCallSeqFinally g m elemTy arg1 arg2 =
mkApps g (typedExprForIntrinsic g m g.seq_finally_info, [[elemTy]], [ arg1; arg2 ], m)

let mkCallSeqTryWith g m elemTy origSeq exnFilter exnHandler =
mkApps g (typedExprForIntrinsic g m g.seq_trywith_info, [[elemTy]], [ origSeq; exnFilter; exnHandler ], m)

let mkCallSeqOfFunctions g m ty1 ty2 arg1 arg2 arg3 =
mkApps g (typedExprForIntrinsic g m g.seq_of_functions_info, [[ty1;ty2]], [ arg1; arg2; arg3 ], m)
Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/TypedTree/TypedTreeOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,8 @@ val mkCallSeqAppend: TcGlobals -> range -> TType -> Expr -> Expr -> Expr

val mkCallSeqFinally: TcGlobals -> range -> TType -> Expr -> Expr -> Expr

val mkCallSeqTryWith: TcGlobals -> range -> TType -> Expr -> Expr -> Expr -> Expr

val mkCallSeqGenerated: TcGlobals -> range -> TType -> Expr -> Expr -> Expr

val mkCallSeqOfFunctions: TcGlobals -> range -> TType -> TType -> Expr -> Expr -> Expr -> Expr
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">reprezentace struktury aktivních vzorů</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">Vyvolá upozornění, když se použije „let inline ... =“ společně s atributem [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;]. Funkce není vkládána.</target>
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">Strukturdarstellung für aktive Muster</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">Löst Warnungen aus, wenn „let inline ... =“ zusammen mit dem Attribut [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] verwendet wird. Die Funktion wird nicht inline gesetzt.</target>
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">representación de struct para modelos activos</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">Genera advertencias cuando se usa "let inline ... =" junto con el atributo [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;]. La función no se está insertando.</target>
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">représentation de structure pour les modèles actifs</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">Génère des avertissements lorsque « let inline ... = » est utilisé avec l’attribut [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;]. La fonction n’est pas inlined.</target>
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">rappresentazione struct per criteri attivi</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">Genera avvisi quando 'let inline ... =' viene usato insieme all'attributo [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;]. La funzione non viene resa inline.</target>
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">アクティブなパターンの構造体表現</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">'let inline ... =' が [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] 属性と一緒に使用されるときに警告を生成します。関数はインライン化されていません。</target>
Expand Down
8 changes: 8 additions & 0 deletions src/Compiler/xlf/FSComp.txt.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,19 @@
<target state="translated">활성 패턴에 대한 구조체 표현</target>
<note />
</trans-unit>

<trans-unit id="featureTryWithInSeqExpressions">
<source>Support for try-with in sequence expressions</source>
<target state="new">Support for try-with in sequence expressions</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenCopyAndUpdateRecordChangesAllFields">
<source>Raises warnings when an copy-and-update record expression changes all fields of a record.</source>
<target state="new">Raises warnings when an copy-and-update record expression changes all fields of a record.</target>
<note />
</trans-unit>

<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="translated">'let inline ... ='을(를) [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] 특성과 함께 사용하는 경우 경고를 발생합니다. 함수가 인라인되지 않습니다.</target>
Expand Down
Loading