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

Impossible record extension inference causes out of memory crash #1691

Open
dcecile opened this issue Mar 18, 2018 · 1 comment
Open

Impossible record extension inference causes out of memory crash #1691

dcecile opened this issue Mar 18, 2018 · 1 comment

Comments

@dcecile
Copy link

dcecile commented Mar 18, 2018

(The result is the same as #1669, but by my understanding I'd say this is a type contradiction not an infinite type.)

With the following code (or full Main.elm), the Elm 0.18 compiler hangs and eventually crashes due to out of memory:

type alias FullRecord =
    { fieldA : String
    , fieldB : Maybe String
    }


type alias PartialRecordA a =
    { a
        | fieldA : String
    }


type alias PartialRecordB a =
    { a
        | fieldB : String
    }


fullRecord : PartialRecordA a -> Maybe (PartialRecordB b) -> FullRecord
fullRecord partialRecordA partialRecordB =
    { fieldA = partialRecordA.fieldA
    , fieldB = Maybe.map .fieldB partialRecordB
    }


combineA : PartialRecordA a -> FullRecord
combineA =
    combineMaybeAB (always Nothing)


combineAB : PartialRecordA (PartialRecordB a) -> FullRecord
combineAB =
    combineMaybeAB Just



combineMaybeAB : (PartialRecordA a -> Maybe (PartialRecordB a)) -> PartialRecordA a -> FullRecord -- Hangs
--combineMaybeAB : (PartialRecordA a -> Maybe (PartialRecordB b)) -> PartialRecordA a -> FullRecord -- Works
combineMaybeAB partialSelectorB partialRecordA =
    fullRecord partialRecordA (partialSelectorB partialRecordA)

The type inference is impossible because no single a can satisfy both PartialRecordA a and PartialRecordA (PartialRecordB a) when combineAB calls combineMaybeAB. (The second a needs to have fewer fields.) Instead of giving an error message, the compiler gets stuck and keeps allocating more memory.

If combineAB is written with parameters instead of point-free, the correct compiler message gets generated.

If the correct type signature for combineMaybeAB is used, the compile succeeds and doesn't hang.

@process-bot
Copy link

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants