Git Product home page Git Product logo

Comments (4)

vladima avatar vladima commented on May 11, 2024

minified repro

type Class1() =

    static member A(a: 'a) = ()
    static member B(rng: 'b) =
        let rec go a =
            if a then go a
            else <@@ rng  @@>
        1

from fsharp.

dsyme avatar dsyme commented on May 11, 2024

@vladima discussed with me that the underlying cause is the reallocation of the reference cell in the Expr.Quote node by the "instExpr" operation inside ChooseTyparSolutionsForFreeChoiceTypars. This means "check.fs" doesn't correctly fill in the AST value of the quotation for the untyped quotation.

| Expr.Quote (a,{contents=None},isFromQueryExpression,m,ty) ->  
    Expr.Quote (remapExpr g (fixValCopyFlagForQuotations compgen) tmenv a,{contents=None},isFromQueryExpression,m,remapType tmenv ty)

I believe this node should not be reallocated in this pass. I suggest adding a new flag CloneAllKeepReferenceCells to ValCopyFlag:

type ValCopyFlag = 
    | CloneAll
    | CloneAllKeepReferenceCells  <-- add this
    | CloneAllAndMarkExprValsAsCompilerGenerated
    | OnlyCloneExprVals

and adding a boolean flag into instExpr and ChooseTyparSolutionsForFreeChoiceTypars which activates this flag, and returning the original reference cell when this flag is active

| Expr.Quote (a,({contents=None} as origRefCell),isFromQueryExpression,m,ty) ->  

We may have to review additional code paths at the callers to these two functions, though initially assume that the flag doesn't have to be set on any other code paths.

Cheers
Don

from fsharp.

vladima avatar vladima commented on May 11, 2024

unfortunately after a deeper look this approach will not work. If ref cell is not reallocated then after running check phase on the node produced by instExpr then it might be filled with transient data that does not match the rest of the tree. i.e if instExpr can copy some Val and this Val is captured in quotation then ref cell will save information about this copied Val and this will cause crash on other compilation steps later. As an option we can extract code that creates quotations from the check into the separate phase so it will always use consistent view of the tree

from fsharp.

KevinRansom avatar KevinRansom commented on May 11, 2024

Has been fixed.

from fsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.