Skip to content

Impossible record extension inference causes out of memory crash #1691

Open
@dcecile

Description

@dcecile

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions