Stabel

Check-in [8ca0797438]
Login
Overview
Comment:Display source code for errors thrown in TestCompiler when compiling projects.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 8ca07974380d1582d3bdca60347ce5c3f1617beccecfb85b574552f25cf35c81
User & Date: robin.hansen on 2021-08-02 10:20:30
Other Links: manifest | tags
Context
2021-08-02
10:25
Include types of bound union members in named unions. check-in: 1810037cab user: robin.hansen tags: trunk
10:20
Display source code for errors thrown in TestCompiler when compiling projects. check-in: 8ca0797438 user: robin.hansen tags: trunk
2021-08-01
09:17
Added elm-review config, and updated other dependencies. check-in: 3d05a90b00 user: robin.hansen tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified src/Stabel/Qualifier/Problem.elm from [9d508ed2fa] to [ba5038b59f].

1
2

3
4
5
6
7
8
9
..
60
61
62
63
64
65
66

























module Stabel.Qualifier.Problem exposing
    ( Problem(..)

    , toString
    )

import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)


type Problem
................................................................................

        TypeNotExposed range typeRef ->
            SourceLocation.extractFromString source range.start range.end
                ++ "\n\n"
                ++ "Referencing '"
                ++ typeRef
                ++ "' but this type is not exposed."



























>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
..
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
module Stabel.Qualifier.Problem exposing
    ( Problem(..)
    , sourceLocationRef
    , toString
    )

import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)


type Problem
................................................................................

        TypeNotExposed range typeRef ->
            SourceLocation.extractFromString source range.start range.end
                ++ "\n\n"
                ++ "Referencing '"
                ++ typeRef
                ++ "' but this type is not exposed."


sourceLocationRef : Problem -> String
sourceLocationRef problem =
    case problem of
        UnknownFunctionRef range _ ->
            range.source

        UnknownTypeRef range _ ->
            range.source

        UnionTypeMatchWithPatterns range ->
            range.source

        InvalidTypeMatch range ->
            range.source

        NoSuchMemberOnType range _ _ ->
            range.source

        FunctionNotExposed range _ ->
            range.source

        TypeNotExposed range _ ->
            range.source

Modified src/Stabel/TypeChecker/Problem.elm from [ad8f11cdf9] to [6cad9e5a48].

1
2

3
4
5
6
7
8
9
..
66
67
68
69
70
71
72






















module Stabel.TypeChecker.Problem exposing
    ( Problem(..)

    , toString
    )

import Set exposing (Set)
import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)
import Stabel.Data.Type as Type exposing (FunctionType, Type)

................................................................................
                formatTypePattern tp =
                    String.join " -> " (List.map Type.toDisplayString tp)
            in
            SourceLocation.extractFromString source range.start range.end
                ++ "\n\n"
                ++ "This multi-function doesn't handle all potential patterns. Missing patterns for:\n\n"
                ++ String.join "\n" (List.map formatTypePattern missingTypes)
























>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
..
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
module Stabel.TypeChecker.Problem exposing
    ( Problem(..)
    , sourceLocationRef
    , toString
    )

import Set exposing (Set)
import Stabel.Data.SourceLocation as SourceLocation exposing (SourceLocationRange)
import Stabel.Data.Type as Type exposing (FunctionType, Type)

................................................................................
                formatTypePattern tp =
                    String.join " -> " (List.map Type.toDisplayString tp)
            in
            SourceLocation.extractFromString source range.start range.end
                ++ "\n\n"
                ++ "This multi-function doesn't handle all potential patterns. Missing patterns for:\n\n"
                ++ String.join "\n" (List.map formatTypePattern missingTypes)


sourceLocationRef : Problem -> String
sourceLocationRef problem =
    case problem of
        UndeclaredGeneric range _ _ ->
            range.source

        TypeError range _ _ _ ->
            range.source

        UnexpectedType range _ _ _ ->
            range.source

        InconsistentWhens range _ ->
            range.source

        MissingTypeAnnotationInRecursiveCallStack range _ ->
            range.source

        InexhaustiveMultiFunction range _ ->
            range.source

Modified src/TestCompiler.elm from [ec209e57c3] to [1362aa673b].

131
132
133
134
135
136
137


138
139
140
141
142
143
144
145
...
149
150
151
152
153
154
155


156
157
158
159
160


161
162
163
164
165
166
167
168
...
179
180
181
182
183
184
185
186
187
188
189
190
191





192
193

194

195
196
197
198
199
200
201
202
...
213
214
215
216
217
218
219










220
221
222
223
224










225
226
227
228
229
230
231
232
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
                    compileFailed errmsg


compileString : CompileStringOpts -> Result String Wasm.Module
compileString opts =
    case Parser.run "test" opts.sourceCode of
        Err parserErrors ->


            formatErrors (ParserProblem.toString opts.sourceCode) parserErrors

        Ok ast ->
            let
                qualifierResult =
                    Qualifier.run
                        { packageName = ""
                        , modulePath = ""
................................................................................
                        }

                exportedFunctions =
                    Set.singleton opts.entryPoint
            in
            case qualifierResult of
                Err qualifierErrors ->


                    formatErrors (QualifierProblem.toString opts.sourceCode) qualifierErrors

                Ok qualifiedAst ->
                    case TypeChecker.run qualifiedAst of
                        Err typeErrors ->


                            formatErrors (TypeCheckerProblem.toString opts.sourceCode) typeErrors

                        Ok typedAst ->
                            typedAst
                                |> Codegen.run exportedFunctions
                                |> Ok


................................................................................
    let
        parserResult =
            opts.modules
                |> List.map parseModuleSource
                |> Result.combine

        parseModuleSource mod =
            case Parser.run mod.modulePath mod.source of
                Err err ->
                    Err err

                Ok ast ->
                    Ok ( mod.package, mod.modulePath, ast )





    in
    case parserResult of

        Err errs ->

            formatErrors (ParserProblem.toString "") errs

        Ok withAst ->
            let
                initialConfig =
                    { packageName = ""
                    , modulePath = ""
                    , ast =
................................................................................
                    List.foldl qualifyTestTuples ( [], initialConfig ) withAst

                exportedFunctions =
                    Set.singleton opts.entryPoint
            in
            case qualifierResult of
                ( (_ :: _) as qualifierErrors, _ ) ->










                    formatErrors (QualifierProblem.toString "") qualifierErrors

                ( _, qualifiedAst ) ->
                    case TypeChecker.run qualifiedAst.inProgressAST of
                        Err typeErrors ->










                            formatErrors (TypeCheckerProblem.toString "") typeErrors

                        Ok typedAst ->
                            typedAst
                                |> Codegen.run exportedFunctions
                                |> Ok


................................................................................
                        | inProgressAST = updatedInProgressAst
                        , externalModules = Dict.insert ("/" ++ modulePath) packageName updatedConfig.externalModules
                    }
            in
            ( problems, configWithQualifiedAst )


formatErrors : (a -> String) -> List a -> Result String b
formatErrors fn problems =
    problems
        |> List.map fn
        |> String.join "\n\n"
        |> Err


compileSucceded : Wasm.Module -> Cmd msg
compileSucceded wasm =
    compileFinished ( True, Wasm.toString wasm )







>
>
|







 







>
>
|




>
>
|







 







|
|
|



>
>
>
>
>


>
|
>
|







 







>
>
>
>
>
>
>
>
>
>
|




>
>
>
>
>
>
>
>
>
>
|







 







|


|







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
...
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
...
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
                    compileFailed errmsg


compileString : CompileStringOpts -> Result String Wasm.Module
compileString opts =
    case Parser.run "test" opts.sourceCode of
        Err parserErrors ->
            parserErrors
                |> List.map (Tuple.pair opts.sourceCode)
                |> formatErrors ParserProblem.toString

        Ok ast ->
            let
                qualifierResult =
                    Qualifier.run
                        { packageName = ""
                        , modulePath = ""
................................................................................
                        }

                exportedFunctions =
                    Set.singleton opts.entryPoint
            in
            case qualifierResult of
                Err qualifierErrors ->
                    qualifierErrors
                        |> List.map (Tuple.pair opts.sourceCode)
                        |> formatErrors QualifierProblem.toString

                Ok qualifiedAst ->
                    case TypeChecker.run qualifiedAst of
                        Err typeErrors ->
                            typeErrors
                                |> List.map (Tuple.pair opts.sourceCode)
                                |> formatErrors TypeCheckerProblem.toString

                        Ok typedAst ->
                            typedAst
                                |> Codegen.run exportedFunctions
                                |> Ok


................................................................................
    let
        parserResult =
            opts.modules
                |> List.map parseModuleSource
                |> Result.combine

        parseModuleSource mod =
            case Parser.run (mod.package ++ mod.modulePath) mod.source of
                Err errs ->
                    Err ( mod.source, errs )

                Ok ast ->
                    Ok ( mod.package, mod.modulePath, ast )

        sourceDict =
            opts.modules
                |> List.map (\mod -> ( mod.package ++ mod.modulePath, mod.source ))
                |> Dict.fromList
    in
    case parserResult of
        Err ( sourceCode, errs ) ->
            errs
                |> List.map (Tuple.pair sourceCode)
                |> formatErrors ParserProblem.toString

        Ok withAst ->
            let
                initialConfig =
                    { packageName = ""
                    , modulePath = ""
                    , ast =
................................................................................
                    List.foldl qualifyTestTuples ( [], initialConfig ) withAst

                exportedFunctions =
                    Set.singleton opts.entryPoint
            in
            case qualifierResult of
                ( (_ :: _) as qualifierErrors, _ ) ->
                    qualifierErrors
                        |> List.map
                            (\problem ->
                                ( Dict.get
                                    (QualifierProblem.sourceLocationRef problem)
                                    sourceDict
                                    |> Maybe.withDefault ""
                                , problem
                                )
                            )
                        |> formatErrors QualifierProblem.toString

                ( _, qualifiedAst ) ->
                    case TypeChecker.run qualifiedAst.inProgressAST of
                        Err typeErrors ->
                            typeErrors
                                |> List.map
                                    (\problem ->
                                        ( Dict.get
                                            (TypeCheckerProblem.sourceLocationRef problem)
                                            sourceDict
                                            |> Maybe.withDefault ""
                                        , problem
                                        )
                                    )
                                |> formatErrors TypeCheckerProblem.toString

                        Ok typedAst ->
                            typedAst
                                |> Codegen.run exportedFunctions
                                |> Ok


................................................................................
                        | inProgressAST = updatedInProgressAst
                        , externalModules = Dict.insert ("/" ++ modulePath) packageName updatedConfig.externalModules
                    }
            in
            ( problems, configWithQualifiedAst )


formatErrors : (String -> a -> String) -> List ( String, a ) -> Result String b
formatErrors fn problems =
    problems
        |> List.map (\( source, err ) -> fn source err)
        |> String.join "\n\n"
        |> Err


compileSucceded : Wasm.Module -> Cmd msg
compileSucceded wasm =
    compileFinished ( True, Wasm.toString wasm )

Modified wasm_tests/module_resolution.test.js from [0a7bb800bd] to [9bae11ca61].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
                `
            },
            {
                package: 'author/sample',
                module: 'core',
                source: `
                    def: main
                    : 0 
                      internal/flip
                      internal/inc
                `
            },
        ]
    });








|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
                `
            },
            {
                package: 'author/sample',
                module: 'core',
                source: `
                    def: main
                    : 0
                      internal/flip
                      internal/inc
                `
            },
        ]
    });