diff options
author | martinw | 2000-08-15 11:20:50 +0000 |
---|---|---|
committer | martinw | 2000-08-15 11:20:50 +0000 |
commit | 22fb78252040fdfc120039ba81f0642ddd8ef8b9 (patch) | |
tree | c099ee2371863894cb700e3aa4c508a834e6b555 /frontend | |
parent | added position information to case defaults to improve type error messages (diff) |
improved typing error messages: type variables are printed like "a" instead
of "v314", case defaults and guards now also have file position information.
git-svn-id: https://svn.cs.ru.nl/repos/clean-compiler/trunk@202 1f8540f1-abd5-4d5b-9d24-4c5ce8603e2d
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/StdCompare.dcl | 2 | ||||
-rw-r--r-- | frontend/StdCompare.icl | 8 | ||||
-rw-r--r-- | frontend/check.icl | 16 | ||||
-rw-r--r-- | frontend/frontend.dcl | 4 | ||||
-rw-r--r-- | frontend/frontend.icl | 11 | ||||
-rw-r--r-- | frontend/main.icl | 2 | ||||
-rw-r--r-- | frontend/overloading.icl | 11 | ||||
-rw-r--r-- | frontend/parse.icl | 20 | ||||
-rw-r--r-- | frontend/postparse.icl | 14 | ||||
-rw-r--r-- | frontend/syntax.dcl | 7 | ||||
-rw-r--r-- | frontend/syntax.icl | 39 | ||||
-rw-r--r-- | frontend/type.dcl | 5 | ||||
-rw-r--r-- | frontend/type.icl | 158 | ||||
-rw-r--r-- | frontend/typesupport.dcl | 13 | ||||
-rw-r--r-- | frontend/typesupport.icl | 285 | ||||
-rw-r--r-- | frontend/unitype.dcl | 2 | ||||
-rw-r--r-- | frontend/unitype.icl | 63 |
17 files changed, 434 insertions, 226 deletions
diff --git a/frontend/StdCompare.dcl b/frontend/StdCompare.dcl index 5839af4..72491e3 100644 --- a/frontend/StdCompare.dcl +++ b/frontend/StdCompare.dcl @@ -14,7 +14,7 @@ instance =< Int, Expression, {# Char}, Ident, [a] | =< a, BasicType //, (Global instance =< Type, SymbIdent instance == BasicType, TypeVar, TypeSymbIdent, DefinedSymbol, TypeContext , BasicValue, - FunKind, (Global a) | == a, Priority, Assoc + FunKind, (Global a) | == a, Priority, Assoc, Type instance < MemberDef diff --git a/frontend/StdCompare.icl b/frontend/StdCompare.icl index b9785ca..4dc82c4 100644 --- a/frontend/StdCompare.icl +++ b/frontend/StdCompare.icl @@ -74,6 +74,14 @@ where = type1 == type2 && types1 == types2 equal_constructor_args (TQV varid1) (TQV varid2) = varid1 == varid2 +// MW4.. + equal_constructor_args (GTV varid1) (GTV varid2) + = varid1 == varid2 + equal_constructor_args (TempQV varid1) (TempQV varid2) + = varid1 == varid2 + equal_constructor_args (TLifted varid1) (TLifted varid2) + = varid1 == varid2 +// ..MW4 equal_constructor_args type1 type2 = True diff --git a/frontend/check.icl b/frontend/check.icl index 883e81f..ba336a5 100644 --- a/frontend/check.icl +++ b/frontend/check.icl @@ -1867,19 +1867,19 @@ where check_default_expr free_vars No e_input e_state e_info cs = (No, free_vars, e_state, e_info, cs) - convert_guards_to_cases [(let_binds, guard, expr)] result_expr es_expr_heap + convert_guards_to_cases [(let_binds, guard, expr, guard_ident)] result_expr es_expr_heap # (case_expr_ptr, es_expr_heap) = newPtr EI_Empty es_expr_heap basic_pattern = {bp_value = (BVB True), bp_expr = expr, bp_position = NoPos } case_expr = Case { case_expr = guard, case_guards = BasicPatterns BT_Bool [basic_pattern], - case_default = result_expr, case_ident = No, case_info_ptr = case_expr_ptr, - case_default_pos = NoPos } + case_default = result_expr, case_ident = Yes guard_ident, + case_info_ptr = case_expr_ptr, case_default_pos = NoPos } = build_sequential_lets let_binds case_expr es_expr_heap - convert_guards_to_cases [(let_binds, guard, expr) : rev_guarded_exprs] result_expr es_expr_heap + convert_guards_to_cases [(let_binds, guard, expr, guard_ident) : rev_guarded_exprs] result_expr es_expr_heap # (case_expr_ptr, es_expr_heap) = newPtr EI_Empty es_expr_heap basic_pattern = {bp_value = (BVB True), bp_expr = expr, bp_position = NoPos } case_expr = Case { case_expr = guard, case_guards = BasicPatterns BT_Bool [basic_pattern], - case_default = result_expr, case_ident = No, case_info_ptr = case_expr_ptr, - case_default_pos = NoPos } + case_default = result_expr, case_ident = Yes guard_ident, + case_info_ptr = case_expr_ptr, case_default_pos = NoPos } (result_expr, es_expr_heap) = build_sequential_lets let_binds case_expr es_expr_heap = convert_guards_to_cases rev_guarded_exprs (Yes result_expr) es_expr_heap @@ -1890,14 +1890,14 @@ where check_guarded_expressions free_vars [] let_vars_list rev_guarded_exprs {ei_expr_level} e_state e_info cs = (let_vars_list, rev_guarded_exprs, ei_expr_level, free_vars, e_state, e_info, cs) - check_guarded_expression free_vars {alt_nodes,alt_guard,alt_expr} + check_guarded_expression free_vars {alt_nodes,alt_guard,alt_expr,alt_ident} let_vars_list rev_guarded_exprs e_input=:{ei_expr_level,ei_mod_index} e_state e_info cs # (let_binds, let_vars_list, ei_expr_level, free_vars, e_state, e_info, cs) = check_sequential_lets free_vars alt_nodes let_vars_list { e_input & ei_expr_level = inc ei_expr_level } e_state e_info cs e_input = { e_input & ei_expr_level = ei_expr_level } (guard, free_vars, e_state, e_info, cs) = checkExpression free_vars alt_guard e_input e_state e_info cs (expr, free_vars, e_state, e_info, cs) = check_opt_guarded_alts free_vars alt_expr e_input e_state e_info cs - = (let_vars_list, [(let_binds, guard, expr) : rev_guarded_exprs], ei_expr_level, free_vars, e_state, e_info, cs ) + = (let_vars_list, [(let_binds, guard, expr, alt_ident) : rev_guarded_exprs], ei_expr_level, free_vars, e_state, e_info, cs ) // JVG: added type check_unguarded_expression :: [FreeVar] ExprWithLocalDefs ExpressionInput *ExpressionState *ExpressionInfo *CheckState -> *(!Expression,![FreeVar],!*ExpressionState,!*ExpressionInfo,!*CheckState); diff --git a/frontend/frontend.dcl b/frontend/frontend.dcl index 69d1626..a41ccbe 100644 --- a/frontend/frontend.dcl +++ b/frontend/frontend.dcl @@ -22,5 +22,5 @@ import checksupport, transform, overloading | FrontEndPhaseConvertModules | FrontEndPhaseAll -frontEndInterface :: !FrontEndPhase !Ident !SearchPaths !*PredefinedSymbols !*HashTable !*Files !*File !*File !*File -> (!*PredefinedSymbols, !*HashTable, !*Files, !*File, !*File, !*File, !Optional *FrontEndSyntaxTree) -// upToPhase name paths predefs files error io out
\ No newline at end of file +frontEndInterface :: !FrontEndPhase !Ident !SearchPaths !Bool !*PredefinedSymbols !*HashTable !*Files !*File !*File !*File -> (!*PredefinedSymbols, !*HashTable, !*Files, !*File, !*File, !*File, !Optional *FrontEndSyntaxTree) +// upToPhase name paths list_inferred_types predefs files error io out
\ No newline at end of file diff --git a/frontend/frontend.icl b/frontend/frontend.icl index 32e8da5..cb23a06 100644 --- a/frontend/frontend.icl +++ b/frontend/frontend.icl @@ -72,8 +72,8 @@ instance == FrontEndPhase where (==) a b = equal_constructor a b -frontEndInterface :: !FrontEndPhase !Ident !SearchPaths !*PredefinedSymbols !*HashTable !*Files !*File !*File !*File -> (!*PredefinedSymbols, !*HashTable, !*Files, !*File, !*File, !*File, !Optional *FrontEndSyntaxTree) -frontEndInterface upToPhase mod_ident search_paths predef_symbols hash_table files error io out +frontEndInterface :: !FrontEndPhase !Ident !SearchPaths !Bool !*PredefinedSymbols !*HashTable !*Files !*File !*File !*File -> (!*PredefinedSymbols, !*HashTable, !*Files, !*File, !*File, !*File, !Optional *FrontEndSyntaxTree) +frontEndInterface upToPhase mod_ident search_paths list_inferred_types predef_symbols hash_table files error io out # (ok, mod, hash_table, error, predef_symbols, files) = wantModule cWantIclFile mod_ident NoPos (hash_table -*-> ("Parsing:", mod_ident)) error search_paths predef_symbols files | not ok @@ -101,8 +101,9 @@ frontEndInterface upToPhase mod_ident search_paths predef_symbols hash_table fil = frontSyntaxTree predef_symbols hash_table files error io out icl_mod dcl_mods fun_defs components array_instances var_heap optional_dcl_icl_conversions global_fun_range - # (ok, fun_defs, array_instances, type_code_instances, common_defs, imported_funs, heaps, predef_symbols, error) - = typeProgram (components -*-> "Typing") fun_defs icl_specials icl_common icl_declared.dcls_import dcl_mods heaps predef_symbols error + # (ok, fun_defs, array_instances, type_code_instances, common_defs, imported_funs, heaps, predef_symbols, error, out) + = typeProgram (components -*-> "Typing") fun_defs icl_specials list_inferred_types icl_common + icl_declared.dcls_import dcl_mods heaps predef_symbols error out | not ok = (predef_symbols, hash_table, files, error, io, out, No) @@ -227,4 +228,4 @@ where # (fun_def, fun_defs) = fun_defs![fun] # properties = { form_properties = cAttributed bitor cAnnotated, form_attr_position = No } (Yes ftype) = fun_def.fun_type - = show_types funs fun_defs (file <<< fun_def.fun_symb <<< " :: " <:: (properties, ftype) <<< '\n' ) + = show_types funs fun_defs (file <<< fun_def.fun_symb <<< " :: " <:: (properties, ftype, No) <<< '\n' ) diff --git a/frontend/main.icl b/frontend/main.icl index 0791130..2b0d7ff 100644 --- a/frontend/main.icl +++ b/frontend/main.icl @@ -147,7 +147,7 @@ compileModule mod_name ms loadModule mod_ident predef_symbols hash_table ms=:{ms_files,ms_error,ms_io,ms_out,ms_paths} # (predef_symbols, hash_table, ms_files, ms_error, ms_io, ms_out, optional_syntax_tree) - = frontEndInterface FrontEndPhaseAll mod_ident {sp_locations = [], sp_paths = ms_paths} predef_symbols hash_table ms_files ms_error ms_io ms_out + = frontEndInterface FrontEndPhaseAll mod_ident {sp_locations = [], sp_paths = ms_paths} False predef_symbols hash_table ms_files ms_error ms_io ms_out ms = {ms & ms_files=ms_files, ms_error=ms_error,ms_io=ms_io,ms_out=ms_out} = case optional_syntax_tree of diff --git a/frontend/overloading.icl b/frontend/overloading.icl index 78e6657..2f1306a 100644 --- a/frontend/overloading.icl +++ b/frontend/overloading.icl @@ -93,19 +93,24 @@ where instanceError symbol types err # err = errorHeading "Overloading error" err format = { form_properties = cNoProperties, form_attr_position = No } - = { err & ea_file = err.ea_file <<< " \"" <<< symbol <<< "\" no instance available of type " <:: (format, types) <<< '\n' } +// MW4 was: = { err & ea_file = err.ea_file <<< " \"" <<< symbol <<< "\" no instance available of type " <:: (format, types) <<< '\n' } + = { err & ea_file = err.ea_file <<< " \"" <<< symbol <<< "\" no instance available of type " + <:: (format, types, Yes initialTypeVarBeautifulizer) <<< '\n' } uniqueError symbol types err # err = errorHeading "Overloading/Uniqueness error" err format = { form_properties = cAnnotated, form_attr_position = No } = { err & ea_file = err.ea_file <<< " \"" <<< symbol - <<< "\" uniqueness specification of instance conflicts with current application " <:: (format, types) <<< '\n'} +// MW4 was: <<< "\" uniqueness specification of instance conflicts with current application " <:: (format, types) <<< '\n'} + <<< "\" uniqueness specification of instance conflicts with current application " + <:: (format, types, Yes initialTypeVarBeautifulizer) <<< '\n'} unboxError type err # err = errorHeading "Overloading error of Array class" err format = { form_properties = cNoProperties, form_attr_position = No } - = { err & ea_file = err.ea_file <<< ' ' <:: (format, type) <<< " instance cannot be unboxed\n"} +// MW4 was: = { err & ea_file = err.ea_file <<< ' ' <:: (format, type) <<< " instance cannot be unboxed\n"} + = { err & ea_file = err.ea_file <<< ' ' <:: (format, type, Yes initialTypeVarBeautifulizer) <<< " instance cannot be unboxed\n"} overloadingError op_symb err # err = errorHeading "Overloading error" err diff --git a/frontend/parse.icl b/frontend/parse.icl index d5f6a60..277a522 100644 --- a/frontend/parse.icl +++ b/frontend/parse.icl @@ -115,7 +115,9 @@ stringToIdent ident ident_class pState=:{ps_hash_table} internalIdent :: !String !*ParseState -> (!Ident, !*ParseState) internalIdent prefix pState # ({fp_line,fp_col},pState=:{ps_hash_table}) = getPosition pState - case_string = prefix +++ toString fp_line +++ "_" +++ toString fp_col +// MW4 was: (changed to make it compatible with conventions used in postparse) +// case_string = prefix +++ toString fp_line +++ "_" +++ toString fp_col + case_string = prefix +++ ";" +++ toString fp_line +++ ";" +++ toString fp_col (case_ident, ps_hash_table) = putIdentInHashTable case_string IC_Expression ps_hash_table = (case_ident, { pState & ps_hash_table = ps_hash_table } ) @@ -643,7 +645,8 @@ where want_FunctionBody :: !Token ![NodeDefWithLocals] ![GuardedExpr] !(Token -> Bool) !ParseState -> (!OptGuardedAlts, !ParseState) want_FunctionBody BarToken nodeDefs alts sep pState // # (lets, pState) = want_StrictLet pState // removed from 2.0 - # (token, pState) = nextToken FunctionContext pState + # (guard_position, pState) = getPosition pState // MW4++ + (token, pState) = nextToken FunctionContext pState | token == OtherwiseToken # (token, pState) = nextToken FunctionContext pState (nodeDefs2, token, pState) = want_LetBefores token pState @@ -663,16 +666,25 @@ where offside = position.fp_col (expr, pState) = want_FunctionBody token nodeDefs2 [] sep pState pState = wantEndNestedGuard (default_found expr) offside pState - alt = { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr } +// MW4 was: alt = { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr } + alt = { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr, + alt_ident = guard_ident guard_position.fp_line } (token, pState) = nextToken FunctionContext pState (nodeDefs, token, pState) = want_LetBefores token pState = want_FunctionBody token nodeDefs [alt:alts] sep pState // otherwise # (expr, pState) = root_expression True token nodeDefs2 [] sep pState - alt = { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr } +// MW4 was: alt = { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr } + alt = { alt_nodes = nodeDefs, alt_guard = guard, alt_expr = expr, + alt_ident = guard_ident guard_position.fp_line } (token, pState) = nextToken FunctionContext pState (nodeDefs, token, pState) = want_LetBefores token pState = want_FunctionBody token nodeDefs [alt:alts] sep pState +// MW4.. + where + guard_ident line_nr + = { id_name = "_g;" +++ toString line_nr +++ ";", id_info = nilPtr } +// ..MW4 want_FunctionBody token nodeDefs alts sep pState = root_expression localsExpected token nodeDefs (reverse alts) sep pState diff --git a/frontend/postparse.icl b/frontend/postparse.icl index eea5437..8a10a7e 100644 --- a/frontend/postparse.icl +++ b/frontend/postparse.icl @@ -565,14 +565,17 @@ makeComprehensions [{tq_generators, tq_filter, tq_end, tq_call, tq_lhs_args, tq_ failure = continue rhs - = build_rhs generators success optional_filter failure end +// MW4 was: = build_rhs generators success optional_filter failure end + = build_rhs generators success optional_filter failure end fun_pos parsed_def // MW3 was: = MakeNewParsedDef fun_ident lhsArgs rhs = MakeNewParsedDef fun_ident lhsArgs rhs fun_pos = (PE_Let cIsStrict (LocalParsedDefs [parsed_def]) call_comprehension, ca) - build_rhs :: [TransformedGenerator] ParsedExpr (Optional ParsedExpr) ParsedExpr ParsedExpr -> Rhs - build_rhs [generator : generators] success optional_filter failure end +// MW4 was: build_rhs :: [TransformedGenerator] ParsedExpr (Optional ParsedExpr) ParsedExpr ParsedExpr -> Rhs + build_rhs :: [TransformedGenerator] ParsedExpr (Optional ParsedExpr) ParsedExpr ParsedExpr Position -> Rhs +// MW4 was: build_rhs [generator : generators] success optional_filter failure end + build_rhs [generator : generators] success optional_filter failure end fun_pos = case_with_default generator.tg_case1 generator.tg_case_end_expr generator.tg_case_end_pattern (foldr (case_end end) (case_with_default generator.tg_case2 generator.tg_element generator.tg_pattern @@ -585,9 +588,12 @@ makeComprehensions [{tq_generators, tq_filter, tq_end, tq_call, tq_lhs_args, tq_ Yes filter -> optGuardedAltToRhs (GuardedAlts [ {alt_nodes = [], alt_guard = filter, alt_expr = UnGuardedExpr - {ewl_nodes = [], ewl_expr = success, ewl_locals = LocalParsedDefs []}}] No) +// MW4 was: {ewl_nodes = [], ewl_expr = success, ewl_locals = LocalParsedDefs []}}] No) + {ewl_nodes = [], ewl_expr = success, ewl_locals = LocalParsedDefs []}, + alt_ident = { id_name ="_f;" +++ toString line_nr +++ ";", id_info = nilPtr }}] No) No -> exprToRhs success + (LinePos _ line_nr) = fun_pos /* +++ remove code duplication (bug in 2.0 with nested cases) case_end :: TransformedGenerator Rhs -> Rhs diff --git a/frontend/syntax.dcl b/frontend/syntax.dcl index 350717d..9605315 100644 --- a/frontend/syntax.dcl +++ b/frontend/syntax.dcl @@ -55,7 +55,7 @@ instance toString Ident | STE_DictCons !ConsDef | STE_DictField !SelectorDef | STE_Called ![Index] /* used during macro expansion to indicate that this function is called */ - + :: Global object = { glob_object :: !object , glob_module :: !Index @@ -876,6 +876,7 @@ cNonRecursiveAppl :== False { alt_nodes :: ![NodeDefWithLocals] , alt_guard :: !ParsedExpr , alt_expr :: !OptGuardedAlts + , alt_ident :: !Ident } :: ExprWithLocalDefs = @@ -1126,7 +1127,7 @@ cIsNotStrict :== False :: CoercionPosition = CP_Expression !Expression | CP_FunArg !Ident !Int // Function symbol, argument position (>=1) - + :: IdentPos = { ip_ident :: !Ident , ip_line :: !Int @@ -1148,7 +1149,7 @@ instance <<< (Module a) | <<< a, ParsedDefinition, InstanceType, AttributeVar, T Position, CaseAlt, AType, FunDef, ParsedExpr, TypeAttribute, (Bind a b) | <<< a & <<< b, ParsedConstructor, (TypeDef a) | <<< a, TypeVarInfo, BasicValue, ATypeVar, TypeRhs, FunctionPattern, (Import from_symbol) | <<< from_symbol, ImportDeclaration, ImportedIdent, CasePatterns, (Optional a) | <<< a, ConsVariable, BasicType, Annotation, Selection, SelectorDef, ConsDef, LocalDefs, FreeVar, ClassInstance, SignClassification, - TypeCodeExpression + TypeCodeExpression, CoercionPosition instance == TypeAttribute instance == Annotation diff --git a/frontend/syntax.icl b/frontend/syntax.icl index fae746d..84729c9 100644 --- a/frontend/syntax.icl +++ b/frontend/syntax.icl @@ -840,6 +840,7 @@ cNotVarNumber :== -1 { alt_nodes :: ![NodeDefWithLocals] , alt_guard :: !ParsedExpr , alt_expr :: !OptGuardedAlts + , alt_ident :: !Ident } :: ExprWithLocalDefs = @@ -1762,6 +1763,44 @@ where (<<<) file (ID_Record ident optIdents) = file <<< ident <<< " { " <<< optIdents <<< " } " (<<<) file (ID_Instance i1 i2 tup) = file <<< "instance " <<< i1 <<< i2 <<< tup // !ImportedIdent !Ident !(![Type],![TypeContext]) +instance <<< CoercionPosition +where + (<<<) file (CP_FunArg fun_name arg_nr) = file <<< "argument " <<< arg_nr <<< " of " <<< readable fun_name + (<<<) file (CP_Expression expression) = show_expression file expression + where + show_expression file (Var {var_name}) + = file <<< var_name + show_expression file (FreeVar {fv_name}) + = file <<< fv_name + show_expression file (App {app_symb={symb_name}, app_args}) + | symb_name.id_name=="_dummyForStrictAlias" + = show_expression file (hd app_args) + = file <<< readable symb_name + show_expression file (fun @ fun_args) + = show_expression file fun + show_expression file (Case {case_ident=No}) + = file <<< "(case ... )" + show_expression file (Selection _ expr selectors) + = file <<< "selection" + show_expression file (Update expr1 selectors expr2) + = file <<< "update" + show_expression file (TupleSelect {ds_arity} elem_nr expr) + = file <<< "argument" <<< (elem_nr + 1) <<< " of " <<< ds_arity <<< "-tuple" + show_expression file (BasicExpr bv _) + = file <<< bv + show_expression file (MatchExpr _ _ expr) + = file <<< "match expression" + show_expression file _ + = file + +readable :: !Ident -> String // somewhat hacky +readable {id_name} + | id_name=="_cons" || id_name=="_nil" + = "list constructor" + | id_name % (0,5) == "_tuple" + = "tuple" + = id_name + instance <<< ImportedIdent where (<<<) file {ii_ident, ii_extended} = file <<< ii_ident <<< ' ' <<< ii_extended diff --git a/frontend/type.dcl b/frontend/type.dcl index 9fe9b24..75390a4 100644 --- a/frontend/type.dcl +++ b/frontend/type.dcl @@ -3,6 +3,9 @@ definition module type import StdArray import syntax, check +/* MW4 was: typeProgram ::!{! Group} !*{# FunDef} !IndexRange !CommonDefs ![Declaration] !{# DclModule} !*Heaps !*PredefinedSymbols !*File -> (!Bool, !*{# FunDef}, !IndexRange, {! GlobalTCType}, !{# CommonDefs}, !{# {# FunType} }, !*Heaps, !*PredefinedSymbols, !*File) - +*/ +typeProgram ::!{! Group} !*{# FunDef} !IndexRange !Bool !CommonDefs ![Declaration] !{# DclModule} !*Heaps !*PredefinedSymbols !*File !*File + -> (!Bool, !*{# FunDef}, !IndexRange, {! GlobalTCType}, !{# CommonDefs}, !{# {# FunType} }, !*Heaps, !*PredefinedSymbols, !*File, !*File) diff --git a/frontend/type.icl b/frontend/type.icl index afd8528..26fe710 100644 --- a/frontend/type.icl +++ b/frontend/type.icl @@ -19,6 +19,7 @@ import RWSDebug , ts_expr_heap :: !.ExpressionHeap , ts_td_infos :: !.TypeDefInfos , ts_error :: !.ErrorAdmin + , ts_out :: !.File // MW4++ } :: TypeCoercion = @@ -167,12 +168,84 @@ where contains_var var_id _ = False +type_error =: "Type error" // MW4++ +type_error_format =: { form_properties = cNoProperties, form_attr_position = No } // MW4++ + +/* MW4 was: cannotUnify t1 t2 position err # err = errorHeading "Type error" err format = { form_properties = cNoProperties, form_attr_position = No } = { err & ea_file = err.ea_file <<< optionalFrontPosition position <<< " cannot unify " <:: (format, t1) <<< " with " <:: (format, t2) <<< position <<< '\n' } +*/ +cannotUnify t1 t2 position=:(CP_Expression expr) err=:{ea_loc=[ip:_]} + = case tryToOptimizePosition expr ip of + Yes ident_pos + # err = pushErrorAdmin ident_pos err + err = errorHeading type_error err + err = popErrorAdmin err + -> { err & ea_file = err.ea_file <<< " cannot unify " <:: (type_error_format, t1, Yes initialTypeVarBeautifulizer) + <<< " with " <:: (type_error_format, t2, Yes initialTypeVarBeautifulizer) <<< '\n' } + _ + -> cannot_unify t1 t2 position err +cannotUnify t1 t2 position err + = cannot_unify t1 t2 position err + +cannot_unify t1 t2 position err + # (err=:{ea_file}) = errorHeading type_error err + ea_file = case position of + CP_FunArg _ _ + -> ea_file <<< "\"" <<< position <<< "\"" + _ + -> ea_file + ea_file = ea_file <<< " cannot unify " <:: (type_error_format, t1, Yes initialTypeVarBeautifulizer) + <<< " with " <:: (type_error_format, t2, Yes initialTypeVarBeautifulizer) + ea_file = case position of + CP_FunArg _ _ + -> ea_file + _ + -> ea_file <<< " near " <<< position + = { err & ea_file = ea_file <<< '\n' } + +// MW4.. +tryToOptimizePosition (Case {case_ident=Yes {id_name}}) ip + = tryToOptimizePositionFromString id_name ip +tryToOptimizePosition (App {app_symb={symb_name}}) ip + = tryToOptimizePositionFromString symb_name.id_name ip +tryToOptimizePosition (fun @ _) ip + = tryToOptimizePosition fun ip + +tryToOptimizePositionFromString id_name ip + # fst_semicolon_index = searchlArrElt ((==) ';') id_name 0 + | fst_semicolon_index < size id_name + # snd_semicolon_index = searchlArrElt ((==) ';') id_name (fst_semicolon_index+1) + prefix = id_name % (0, fst_semicolon_index-1) + line = toInt (id_name % (fst_semicolon_index+1, snd_semicolon_index-1)) + = Yes { ip & ip_ident = { id_name = prefix_to_readable_name prefix, id_info = nilPtr }, ip_line = line } + = No + where + prefix_to_readable_name "_c" = "case" + prefix_to_readable_name "_g" = "guard" + prefix_to_readable_name "_f" = "filter" + prefix_to_readable_name prefix + | prefix.[0] == 'c' + = "comprehension" + | prefix.[0] == 'g' + = "generator" + prefix_to_readable_name _ = abort "fatal error 21 in type.icl" + +// search for an element in an array +searchlArrElt p s i + :== searchl s i + where + searchl s i + | i>=size s + = i + | p s.[i] + = i + = searchl s (i+1) +// ..MW4 class unify a :: !a !a !TypeInput !*{! Type} !*TypeHeaps -> (!Bool, !*{! Type}, !*TypeHeaps) @@ -1438,18 +1511,24 @@ where specification_error type err # err = errorHeading "Type error" err format = { form_properties = cAttributed, form_attr_position = No} - = { err & ea_file = err.ea_file <<< " specified type conflicts with derived type " <:: (format, type) <<< '\n' } +// MW4 was: = { err & ea_file = err.ea_file <<< " specified type conflicts with derived type " <:: (format, type) <<< '\n' } + = { err & ea_file = err.ea_file <<< " specified type conflicts with derived type " + <:: (format, type, Yes initialTypeVarBeautifulizer) <<< '\n' } -cleanUpAndCheckFunctionTypes [] _ _ start_index defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) +// MW4 was:cleanUpAndCheckFunctionTypes [] _ _ start_index defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) +cleanUpAndCheckFunctionTypes [] _ _ start_index _ defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) = (fun_defs, ts) -cleanUpAndCheckFunctionTypes [fun : funs] [ {fe_requirements = {req_case_and_let_exprs}} : reqs] dict_types start_index defs type_contexts coercion_env +// MW4 was:cleanUpAndCheckFunctionTypes [fun : funs] [ {fe_requirements = {req_case_and_let_exprs}} : reqs] dict_types start_index defs type_contexts coercion_env +cleanUpAndCheckFunctionTypes [fun : funs] [ {fe_requirements = {req_case_and_let_exprs}} : reqs] dict_types start_index list_inferred_types defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) # (fd, fun_defs) = fun_defs![fun] dict_ptrs = get_dict_ptrs fun dict_types - (type_var_env, attr_var_env, ts) = clean_up_and_check_function_type fd fun (start_index == fun) defs type_contexts +// MW4 was: (type_var_env, attr_var_env, ts) = clean_up_and_check_function_type fd fun (start_index == fun) defs type_contexts + (type_var_env, attr_var_env, ts) = clean_up_and_check_function_type fd fun (start_index == fun) list_inferred_types defs type_contexts (dict_ptrs ++ req_case_and_let_exprs) coercion_env attr_partition type_var_env attr_var_env ts - = cleanUpAndCheckFunctionTypes funs reqs dict_types start_index defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) +// MW4 was: = cleanUpAndCheckFunctionTypes funs reqs dict_types start_index defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) + = cleanUpAndCheckFunctionTypes funs reqs dict_types start_index list_inferred_types defs type_contexts coercion_env attr_partition type_var_env attr_var_env (fun_defs, ts) where get_dict_ptrs fun_index [] = [] @@ -1458,7 +1537,8 @@ where = ptrs = get_dict_ptrs fun_index dict_types - clean_up_and_check_function_type {fun_symb,fun_pos,fun_type = opt_fun_type} fun is_start_rule defs type_contexts type_ptrs +// MW4 was: clean_up_and_check_function_type {fun_symb,fun_pos,fun_type = opt_fun_type} fun is_start_rule defs type_contexts type_ptrs + clean_up_and_check_function_type {fun_symb,fun_pos,fun_type = opt_fun_type} fun is_start_rule list_inferred_types defs type_contexts type_ptrs coercion_env attr_partition type_var_env attr_var_env ts # (env_type, ts) = ts!ts_fun_env.[fun] # ts = { ts & ts_error = setErrorAdmin (newPosition fun_symb fun_pos) ts.ts_error} @@ -1476,11 +1556,22 @@ where # (clean_fun_type, type_var_env, attr_var_env, ts_type_heaps, ts_var_heap, ts_expr_heap, ts_error) = cleanUpSymbolType is_start_rule cDerivedType exp_fun_type type_contexts type_ptrs coercion_env attr_partition type_var_env attr_var_env ts.ts_type_heaps ts.ts_var_heap ts.ts_expr_heap ts.ts_error +// MW4.. + ts_out = ts.ts_out + ts_out = case list_inferred_types of + False + -> ts_out + _ + # form = { form_properties = cNoProperties, form_attr_position = No } + -> ts_out <<< fun_symb <<< " :: " + <:: (form, clean_fun_type, Yes initialTypeVarBeautifulizer) <<< '\n' +// ..MW4 ts_fun_env = { ts.ts_fun_env & [fun] = CheckedType clean_fun_type } - -> (type_var_env, attr_var_env, { ts & ts_type_heaps = ts_type_heaps, ts_var_heap = ts_var_heap, ts_expr_heap = ts_expr_heap, ts_fun_env = ts_fun_env, ts_error = ts_error }) +// MW4 was: -> (type_var_env, attr_var_env, { ts & ts_type_heaps = ts_type_heaps, ts_var_heap = ts_var_heap, ts_expr_heap = ts_expr_heap, ts_fun_env = ts_fun_env, ts_error = ts_error }) + -> (type_var_env, attr_var_env, { ts & ts_type_heaps = ts_type_heaps, ts_var_heap = ts_var_heap, ts_expr_heap = ts_expr_heap, ts_fun_env = ts_fun_env, ts_error = ts_error, ts_out = ts_out }) check_function_type fun_type tmp_fun_type=:{tst_lifted} clean_fun_type=:{st_arity, st_args, st_vars, st_attr_vars, st_context} type_ptrs - defs fun_env attr_var_env type_heaps expr_heap error + defs fun_env attr_var_env type_heaps expr_heap error # (equi, attr_var_env, type_heaps) = equivalent clean_fun_type tmp_fun_type (length fun_type.st_context) defs attr_var_env type_heaps | equi # type_with_lifted_arg_types = addLiftedArgumentsToSymbolType fun_type tst_lifted st_args st_vars st_attr_vars st_context @@ -1507,12 +1598,14 @@ addLiftedArgumentsToSymbolType st=:{st_arity,st_args,st_vars,st_attr_vars,st_con , fe_location :: !IdentPos } -typeProgram ::!{! Group} !*{# FunDef} !IndexRange !CommonDefs ![Declaration] !{# DclModule} !*Heaps !*PredefinedSymbols !*File - -> (!Bool, !*{# FunDef}, !IndexRange, {! GlobalTCType}, !{# CommonDefs}, !{# {# FunType} }, !*Heaps, !*PredefinedSymbols, !*File) -typeProgram comps fun_defs specials icl_defs imports modules {hp_var_heap, hp_expression_heap, hp_type_heaps} predef_symbols file +// MW4 was:typeProgram ::!{! Group} !*{# FunDef} !IndexRange !CommonDefs ![Declaration] !{# DclModule} !*Heaps !*PredefinedSymbols !*File +typeProgram ::!{! Group} !*{# FunDef} !IndexRange !Bool !CommonDefs ![Declaration] !{# DclModule} !*Heaps !*PredefinedSymbols !*File !*File +// MW4 was: -> (!Bool, !*{# FunDef}, !IndexRange, {! GlobalTCType}, !{# CommonDefs}, !{# {# FunType} }, !*Heaps, !*PredefinedSymbols, !*File) + -> (!Bool, !*{# FunDef}, !IndexRange, {! GlobalTCType}, !{# CommonDefs}, !{# {# FunType} }, !*Heaps, !*PredefinedSymbols, !*File, !*File) +// MW4 was:typeProgram comps fun_defs specials icl_defs imports modules {hp_var_heap, hp_expression_heap, hp_type_heaps} predef_symbols file +typeProgram comps fun_defs specials list_inferred_types icl_defs imports modules {hp_var_heap, hp_expression_heap, hp_type_heaps} predef_symbols file out #! fun_env_size = size fun_defs # ts_error = {ea_file = file, ea_loc = [], ea_ok = True } - ti_common_defs = {{dcl_common \\ {dcl_common} <-: modules } & [cIclModIndex] = icl_defs } ti_functions = {dcl_functions \\ {dcl_functions} <-: modules } @@ -1526,19 +1619,24 @@ typeProgram comps fun_defs specials icl_defs imports modules {hp_var_heap, hp_ex (_, ts_error, class_instances, th_vars, td_infos) = collect_and_check_instances (size icl_defs.com_instance_defs) ti_common_defs state ts = { ts_fun_env = InitFunEnv fun_env_size, ts_var_heap = hp_var_heap, ts_expr_heap = hp_expression_heap, ts_var_store = 0, ts_attr_store = FirstAttrVar, - ts_type_heaps = { hp_type_heaps & th_vars = th_vars }, ts_td_infos = td_infos, ts_error = ts_error } +// MW4 was: ts_type_heaps = { hp_type_heaps & th_vars = th_vars }, ts_td_infos = td_infos, ts_error = ts_error } + ts_type_heaps = { hp_type_heaps & th_vars = th_vars }, ts_td_infos = td_infos, ts_error = ts_error, ts_out = out } ti = { ti_common_defs = ti_common_defs, ti_functions = ti_functions } special_instances = { si_next_array_member_index = fun_env_size, si_array_instances = [], si_next_TC_member_index = 0, si_TC_instances = [] } - # (type_error, fun_defs, predef_symbols, special_instances, ts) = type_components 0 comps class_instances ti (False, fun_defs, predef_symbols, special_instances, ts) +// MW4 was: # (type_error, fun_defs, predef_symbols, special_instances, ts) = type_components 0 comps class_instances ti (False, fun_defs, predef_symbols, special_instances, ts) + # (type_error, fun_defs, predef_symbols, special_instances, ts) = type_components list_inferred_types 0 comps class_instances ti (False, fun_defs, predef_symbols, special_instances, ts) (fun_defs,ts_fun_env) = update_function_types 0 comps ts.ts_fun_env fun_defs - (type_error, fun_defs, predef_symbols, special_instances, {ts_fun_env,ts_error,ts_var_heap, ts_expr_heap, ts_type_heaps}) - = type_instances specials.ir_from specials.ir_to class_instances ti (type_error, fun_defs, predef_symbols, special_instances, - { ts & ts_fun_env = ts_fun_env }) +// MW4 was: (type_error, fun_defs, predef_symbols, special_instances, {ts_fun_env,ts_error,ts_var_heap, ts_expr_heap, ts_type_heaps}) + (type_error, fun_defs, predef_symbols, special_instances, {ts_fun_env,ts_error,ts_var_heap, ts_expr_heap, ts_type_heaps, ts_out}) +// MW4 was: = type_instances specials.ir_from specials.ir_to class_instances ti (type_error, fun_defs, predef_symbols, special_instances, + = type_instances list_inferred_types specials.ir_from specials.ir_to class_instances ti (type_error, fun_defs, predef_symbols, special_instances, + { ts & ts_fun_env = ts_fun_env }) {si_array_instances, si_next_array_member_index, si_next_TC_member_index, si_TC_instances}= special_instances (fun_defs, predef_symbols, ts_type_heaps) = convert_array_instances si_array_instances ti_common_defs fun_defs predef_symbols ts_type_heaps type_code_instances = {createArray si_next_TC_member_index GTT_Function & [gtci_index] = gtci_type \\ {gtci_index, gtci_type} <- si_TC_instances} = (not type_error, fun_defs, { ir_from = fun_env_size, ir_to = si_next_array_member_index }, type_code_instances, ti_common_defs, ti_functions, - {hp_var_heap = ts_var_heap, hp_expression_heap = ts_expr_heap, hp_type_heaps = ts_type_heaps }, predef_symbols, ts_error.ea_file) +// MW4 was: {hp_var_heap = ts_var_heap, hp_expression_heap = ts_expr_heap, hp_type_heaps = ts_type_heaps }, predef_symbols, ts_error.ea_file) + {hp_var_heap = ts_var_heap, hp_expression_heap = ts_expr_heap, hp_type_heaps = ts_type_heaps }, predef_symbols, ts_error.ea_file, ts_out) // ---> ("typeProgram", array_inst_types) where collect_imported_instances imports common_defs dummy error class_instances type_var_heap td_infos @@ -1611,18 +1709,24 @@ where = (error, IT_Node ins it_less it_greater) = (checkError ins_types " instance is overlapping" error, IT_Node ins it_less it_greater) - type_instances ir_from ir_to class_instances ti funs_and_state +// MW4 was: type_instances ir_from ir_to class_instances ti funs_and_state + type_instances list_inferred_types ir_from ir_to class_instances ti funs_and_state | ir_from == ir_to = funs_and_state - # funs_and_state = type_component [ir_from] class_instances ti funs_and_state - = type_instances (inc ir_from) ir_to class_instances ti funs_and_state +// MW4 was: # funs_and_state = type_component [ir_from] class_instances ti funs_and_state + # funs_and_state = type_component list_inferred_types [ir_from] class_instances ti funs_and_state +// MW4 was: = type_instances (inc ir_from) ir_to class_instances ti funs_and_state + = type_instances list_inferred_types (inc ir_from) ir_to class_instances ti funs_and_state - type_components group_index comps class_instances ti funs_and_state +// MW4 was: type_components group_index comps class_instances ti funs_and_state + type_components list_inferred_types group_index comps class_instances ti funs_and_state | group_index == size comps = funs_and_state #! comp = comps.[group_index] - # funs_and_state = type_component comp.group_members class_instances ti funs_and_state - = type_components (inc group_index) comps class_instances ti funs_and_state +// MW4 was: # funs_and_state = type_component comp.group_members class_instances ti funs_and_state + # funs_and_state = type_component list_inferred_types comp.group_members class_instances ti funs_and_state +// MW4 was: = type_components (inc group_index) comps class_instances ti funs_and_state + = type_components list_inferred_types (inc group_index) comps class_instances ti funs_and_state show_component comp fun_defs = foldSt show_fun comp ([], fun_defs) @@ -1637,7 +1741,8 @@ where = (pds_def, predef_symbols) = (NoIndex, predef_symbols) - type_component comp class_instances ti=:{ti_common_defs} (type_error, fun_defs, predef_symbols, special_instances, ts) +// MW4 was: type_component comp class_instances ti=:{ti_common_defs} (type_error, fun_defs, predef_symbols, special_instances, ts) + type_component list_inferred_types comp class_instances ti=:{ti_common_defs} (type_error, fun_defs, predef_symbols, special_instances, ts) # (start_index, predef_symbols) = get_index_of_start_rule predef_symbols # (fun_defs, predef_symbols, cons_variables, ts) = CreateInitialSymbolTypes start_index ti_common_defs comp (fun_defs, predef_symbols, [], ts) (fun_reqs, (cons_variables, fun_defs, ts)) = type_functions comp ti cons_variables fun_defs ts @@ -1671,7 +1776,8 @@ where (subst, ts_fun_env) = expand_function_types comp subst ts.ts_fun_env attr_var_env = createArray nr_of_attr_vars TA_None var_env = { subst & [i] = TE \\ i <- [0..dec ts_var_store]} - (fun_defs, ts) = cleanUpAndCheckFunctionTypes comp fun_reqs dict_types start_index ti_common_defs contexts coer_demanded attr_partition var_env attr_var_env +// MW4 was: (fun_defs, ts) = cleanUpAndCheckFunctionTypes comp fun_reqs dict_types start_index ti_common_defs contexts coer_demanded attr_partition var_env attr_var_env + (fun_defs, ts) = cleanUpAndCheckFunctionTypes comp fun_reqs dict_types start_index list_inferred_types ti_common_defs contexts coer_demanded attr_partition var_env attr_var_env (fun_defs, { ts & ts_error = ts_error, ts_fun_env = ts_fun_env, ts_type_heaps = ts_type_heaps, ts_td_infos = ts_td_infos, ts_var_heap = os_var_heap, ts_expr_heap = os_symbol_heap }) | not ts.ts_error.ea_ok diff --git a/frontend/typesupport.dcl b/frontend/typesupport.dcl index 0155406..a5d4da3 100644 --- a/frontend/typesupport.dcl +++ b/frontend/typesupport.dcl @@ -9,7 +9,10 @@ SwitchFusion fuse dont_fuse :== dont_fuse errorHeading :: !String !*ErrorAdmin -> *ErrorAdmin -class (<::) infixl a :: !*File (!Format, !a) -> *File +// MW4 was:class (<::) infixl a :: !*File (!Format, !a) -> *File +(<::) infixl :: !*File (!Format, !a, !Optional TypeVarBeautifulizer) -> *File | writeType a + +class writeType a :: !*File !(Optional TypeVarBeautifulizer) (!Format, !a) -> (!*File, !Optional TypeVarBeautifulizer) :: Format = { form_properties :: !BITVECT @@ -21,7 +24,11 @@ cAttributed :== 1 cAnnotated :== 2 cMarkAttribute :== 4 -instance <:: SymbolType, Type, AType, [a] | <:: a +:: TypeVarBeautifulizer // MW++ + +instance writeType SymbolType, Type, AType, [a] | writeType a + +initialTypeVarBeautifulizer :: TypeVarBeautifulizer // MW4++ :: AttributeEnv :== {! TypeAttribute } :: VarEnv :== {! Type } @@ -65,5 +72,3 @@ class substitute a :: !a !*TypeHeaps -> (!a, !*TypeHeaps) instance substitute AType, Type, TypeContext, AttrInequality, CaseType, [a] | substitute a instance <<< TempSymbolType - -optionalFrontPosition :: !CoercionPosition -> String // MW3++ diff --git a/frontend/typesupport.icl b/frontend/typesupport.icl index a474625..fc84b32 100644 --- a/frontend/typesupport.icl +++ b/frontend/typesupport.icl @@ -827,100 +827,123 @@ checkProperty form property :== not (form.form_properties bitand property == 0) setProperty form property :== {form & form_properties = form.form_properties bitor property} clearProperty form property :== {form & form_properties = form.form_properties bitand (bitnot property)} -class (<::) infixl a :: !*File (!Format, !a) -> *File +(<::) infixl :: !*File (!Format, !a, !Optional TypeVarBeautifulizer) -> *File | writeType a +(<::) file (format, a, opt_beautifulizer) + # (file, _) = writeType file opt_beautifulizer (format, a) + = file + +class writeType a :: !*File !(Optional TypeVarBeautifulizer) (!Format, !a) -> (!*File, !Optional TypeVarBeautifulizer) -instance <:: SymbolType +instance writeType SymbolType where - (<::) file (form, {st_args, st_arity, st_result, st_context, st_attr_env}) - | st_arity > 0 - = show_environment form (show_context form (file <:: (form, st_args) <<< " -> " <:: (form, st_result)) st_context) st_attr_env - = show_environment form ((show_context form (file <:: (form, st_result))) st_context) st_attr_env + writeType file opt_beautifulizer (form, {st_args, st_arity, st_result, st_context, st_attr_env}) + # file_opt_beautifulizer + = case st_arity of + 0 + -> writeType file opt_beautifulizer (form, st_result) + _ + # (file, opt_beautifulizer) + = writeType file opt_beautifulizer (form, st_args) + -> writeType (file <<< " -> ") opt_beautifulizer (form, st_result) + (file, opt_beautifulizer) + = show_context form st_context file_opt_beautifulizer + = case isEmpty st_attr_env || not (checkProperty form cAttributed) of + True + -> (file, opt_beautifulizer) + False + # (file, opt_beautifulizer) + = writeType (file <<< ", [") opt_beautifulizer + (setProperty form cCommaSeparator, st_attr_env) + -> (file <<< ']', opt_beautifulizer) where - show_context form file [] - = file - show_context form file contexts - = file <<< " | " <:: (setProperty form cCommaSeparator, contexts) - - show_environment form file [] - = file - show_environment form file environ - = file <<< ", " <:: (setProperty form cCommaSeparator, environ) + show_context form [] file_opt_beautifulizer + = file_opt_beautifulizer + show_context form contexts (file, opt_beautifulizer) + = writeType (file <<< " | ") opt_beautifulizer (setProperty form cCommaSeparator, contexts) -instance <:: TypeContext +instance writeType TypeContext where - (<::) file (form, {tc_class={glob_object={ds_ident}}, tc_types}) - = file <<< ds_ident <<< ' ' <:: (form, tc_types) + writeType file opt_beautifulizer (form, {tc_class={glob_object={ds_ident}}, tc_types}) + = writeType (file <<< ds_ident <<< ' ') opt_beautifulizer (form, tc_types) -instance <:: AttrInequality +instance writeType AttrInequality where - (<::) file (form, {ai_demanded, ai_offered}) - = file <<< ai_offered <<< " <= " <<< ai_demanded + writeType file opt_beautifulizer (form, {ai_demanded, ai_offered}) + = (file <<< ai_offered <<< " <= " <<< ai_demanded, opt_beautifulizer) -instance <:: AType +instance writeType AType where - (<::) file (form, {at_attribute, at_annotation, at_type}) + writeType file opt_beautifulizer (form, {at_attribute, at_annotation, at_type}) | checkProperty form cAnnotated - = show_attributed_type (file <<< at_annotation) form at_attribute at_type - = show_attributed_type file form at_attribute at_type + = show_attributed_type (file <<< at_annotation) opt_beautifulizer form at_attribute at_type + = show_attributed_type file opt_beautifulizer form at_attribute at_type where - show_attributed_type file form TA_Multi type + show_attributed_type file opt_beautifulizer form TA_Multi type | checkProperty form cMarkAttribute - = show_marked_attribute TA_Multi form file <:: (form, type) - = file <:: (form, type) - show_attributed_type file form attr type + # (file, opt_beautifulizer) + = show_marked_attribute TA_Multi form file opt_beautifulizer + = writeType file opt_beautifulizer (form, type) + = writeType file opt_beautifulizer (form, type) + show_attributed_type file opt_beautifulizer form attr type | checkProperty form cAttributed - = file <<< attr <:: (setProperty form cBrackets, type) + = writeType (file <<< attr) opt_beautifulizer (setProperty form cBrackets, type) | checkProperty form cMarkAttribute - = show_marked_attribute attr form file <:: (setProperty form cBrackets, type) - = file <:: (form, type) + # (file, opt_beautifulizer) + = show_marked_attribute attr form file opt_beautifulizer + = writeType file opt_beautifulizer (setProperty form cBrackets, type) + = writeType file opt_beautifulizer (form, type) - show_marked_attribute attr {form_attr_position = Yes (positions, coercions)} file + show_marked_attribute attr {form_attr_position = Yes (positions, coercions)} file opt_beautifulizer | isEmpty positions - = show_attribute attr coercions (file <<< "^ ") - = show_attribute attr coercions file + = show_attribute attr coercions (file <<< "^ ") opt_beautifulizer + = show_attribute attr coercions file opt_beautifulizer - show_attribute TA_Unique coercions file - = file <<< '*' - show_attribute TA_Multi coercions file - = file - show_attribute (TA_TempVar av_number) coercions file + show_attribute TA_Unique coercions file opt_beautifulizer + = (file <<< '*' , opt_beautifulizer) + show_attribute TA_Multi coercions file opt_beautifulizer + = (file, opt_beautifulizer) + show_attribute (TA_TempVar av_number) coercions file opt_beautifulizer | isUniqueAttribute av_number coercions - = file <<< '*' + = (file <<< '*', opt_beautifulizer) | isNonUniqueAttribute av_number coercions - = file - = file <<< '.' <<< "[[" <<< av_number <<< "]]" - show_attribute TA_TempExVar coercions file - = PA_BUG (file <<< "(E)") (abort "show_attribute TA_TempExVar") - -instance <:: Type -where - (<::) file (form, TV varid) - = file <<< varid - (<::) file (form, TempV tv_number) - = file <<< 'v' <<< tv_number - (<::) file (form, TA {type_name,type_index,type_arity} types) + = (file, opt_beautifulizer) + = (file <<< '.' <<< "[[" <<< av_number <<< "]]", opt_beautifulizer) + show_attribute TA_TempExVar coercions file opt_beautifulizer + = PA_BUG (file <<< "(E)", opt_beautifulizer) (abort "show_attribute TA_TempExVar") + +instance writeType Type +where + writeType file No (form, TV varid) + = (file <<< varid, No) + writeType file No (form, TempV tv_number) + = (file <<< 'v' <<< tv_number, No) + writeType file opt_beautifulizer (form, TA {type_name,type_index,type_arity} types) | is_predefined type_index | is_list type_name - = file <<< '[' <:: (setProperty form cCommaSeparator, types) <<< ']' + = writeWithinBrackets "[" "]" file opt_beautifulizer (setProperty form cCommaSeparator, types) | is_lazy_array type_name - = file <<< '{' <:: (setProperty form cCommaSeparator, types) <<< '}' + = writeWithinBrackets "{" "}" file opt_beautifulizer (setProperty form cCommaSeparator, types) | is_strict_array type_name - = file <<< "{!" <:: (setProperty form cCommaSeparator, types) <<< '}' + = writeWithinBrackets "{!" "}" file opt_beautifulizer (setProperty form cCommaSeparator, types) | is_unboxed_array type_name - = file <<< "{#" <:: (setProperty form cCommaSeparator, types) <<< '}' + = writeWithinBrackets "{#" "}" file opt_beautifulizer (setProperty form cCommaSeparator, types) | is_tuple type_name type_arity - = file <<< '(' <:: (setProperty form cCommaSeparator, types) <<< ')' + = writeWithinBrackets "(" ")" file opt_beautifulizer (setProperty form cCommaSeparator, types) | type_arity == 0 - = file <<< type_name + = (file <<< type_name, opt_beautifulizer) | checkProperty form cBrackets - = file <<< '(' <<< type_name <<< ' ' <:: (form, types) <<< ')' - = file <<< type_name <<< ' ' <:: (setProperty form cBrackets, types) + # (file, opt_beautifulizer) + = writeType (file <<< '(' <<< type_name <<< ' ') opt_beautifulizer (form, types) + = (file <<< ')', opt_beautifulizer) + = writeType (file <<< type_name <<< ' ') opt_beautifulizer (setProperty form cBrackets, types) | type_arity == 0 - = file <<< type_name + = (file <<< type_name, opt_beautifulizer) | checkProperty form cBrackets - = file <<< '(' <<< type_name <<< ' ' <:: (form, types) <<< ')' - = file <<< type_name <<< ' ' <:: (setProperty form cBrackets, types) + # (file, opt_beautifulizer) + = writeType (file <<< '(' <<< type_name <<< ' ') opt_beautifulizer (form, types) + = (file <<< ')', opt_beautifulizer) + = writeType (file <<< type_name <<< ' ') opt_beautifulizer (setProperty form cBrackets, types) where is_predefined {glob_module} = glob_module == cPredefinedModuleIndex @@ -930,59 +953,94 @@ where is_strict_array {id_name} = id_name == "_!array" is_unboxed_array {id_name} = id_name == "_#array" - (<::) file (form, arg_type --> res_type) +// MW4 was: writeType file (form, arg_type --> res_type) + writeType file opt_beautifulizer (form, arg_type --> res_type) | checkProperty form cBrackets - = file <<< '(' <:: (clearProperty (setProperty form cArrowSeparator) cBrackets, [arg_type, res_type]) <<< ')' - = file <:: (setProperty form (cBrackets bitor cArrowSeparator), [arg_type, res_type]) - (<::) file (form, type :@: types) + = writeWithinBrackets "(" ")" file opt_beautifulizer + (clearProperty (setProperty form cArrowSeparator) cBrackets, [arg_type, res_type]) + = writeType file opt_beautifulizer (setProperty form (cBrackets bitor cArrowSeparator), [arg_type, res_type]) + writeType file opt_beautifulizer (form, type :@: types) | checkProperty form cBrackets - = file <<< '(' <<< type <<< ' ' <:: (form, types) <<< ')' - = file <<< type <<< ' ' <:: (setProperty form cBrackets, types) - (<::) file (form, TB tb) - = file <<< tb - (<::) file (form, TQV varid) - = file <<< "E." <<< varid - (<::) file (form, TempQV tv_number) - = file <<< "E." <<< tv_number <<< ' ' - (<::) file (form, TE) - = file <<< "__" - (<::) file (form, type) + # (file, opt_beautifulizer) + = writeType (file <<< '(' <<< type <<< ' ') opt_beautifulizer (form, types) + = (file <<< ')', opt_beautifulizer) + = writeType (file <<< type <<< ' ') opt_beautifulizer (setProperty form cBrackets, types) + writeType file opt_beautifulizer (form, TB tb) + = (file <<< tb, opt_beautifulizer) + writeType file No (form, TQV varid) + = (file <<< "E." <<< varid, No) + writeType file No (form, TempQV tv_number) + = (file <<< "E." <<< tv_number <<< ' ', No) + writeType file opt_beautifulizer (form, TE) + = (file <<< "__", opt_beautifulizer) + writeType file (Yes beautifulizer) (form, type_variable) + = writeBeautifulTypeVar file beautifulizer type_variable + writeType file _ (form, type) = abort ("<:: (Type) (typesupport.icl)" ---> type) - +writeWithinBrackets br_open br_close file opt_beautifulizer (form, types) + # (file, opt_beautifulizer) + = writeType (file <<< br_open) opt_beautifulizer (form, types) + = (file <<< br_close, opt_beautifulizer) + +writeBeautifulTypeVar file beautifulizer=:{tvb_visited, tvb_fresh_vars} type_variable + | sanity_check_failed type_variable + = abort "bug nr 12345 in module typesupport" + = case lookup type_variable tvb_visited of + No + -> (file <<< hd tvb_fresh_vars, Yes { tvb_visited = [(type_variable, hd tvb_fresh_vars):tvb_visited], + tvb_fresh_vars = tl tvb_fresh_vars }) + Yes (_, beautiful_var_name) + -> (file <<< beautiful_var_name, Yes beautifulizer) + where + lookup _ [] = No + lookup t1 [hd=:(t2, _):tl] + | t1==t2 + = Yes hd + = lookup t1 tl + + sanity_check_failed (GTV _) = False + sanity_check_failed (TV _) = False + sanity_check_failed (TempV _) = False + sanity_check_failed (TQV _) = False + sanity_check_failed (TempQV _) = False + sanity_check_failed (TLifted _) = False + sanity_check_failed _ = True + cNoPosition :== -1 -instance <:: [a] | <:: a +instance writeType [a] | writeType a where - (<::) file (form, types) - = show_list 0 form types file + writeType file opt_beautifulizer (form, types) + = show_list 0 form types (file, opt_beautifulizer) where - show_list elem_number form [type] file - | checkProperty form cCommaSeparator - = show_elem elem_number (clearProperty form cCommaSeparator) type file - | checkProperty form cArrowSeparator - = show_elem elem_number (clearProperty form cArrowSeparator) type file - = show_elem elem_number (setProperty form cBrackets) type file - show_list elem_number form [type : types] file + show_list elem_number form [type] file_opt_beautifulizer | checkProperty form cCommaSeparator - = show_list (inc elem_number) form types (show_elem elem_number (clearProperty form cCommaSeparator) type file <<< ',') + = show_elem elem_number (clearProperty form cCommaSeparator) type file_opt_beautifulizer | checkProperty form cArrowSeparator - = show_list (inc elem_number) form types (show_elem elem_number (clearProperty form cArrowSeparator) type file <<< " -> ") - = show_list (inc elem_number) form types (show_elem elem_number (setProperty form cBrackets) type file <<< ' ') + = show_elem elem_number (clearProperty form cArrowSeparator) type file_opt_beautifulizer + = show_elem elem_number (setProperty form cBrackets) type file_opt_beautifulizer + show_list elem_number form [type : types] file_opt_beautifulizer + # (elem_format, seperator) + = if (checkProperty form cCommaSeparator) (clearProperty form cCommaSeparator, ",") + (if (checkProperty form cArrowSeparator) (clearProperty form cArrowSeparator, " -> ") + (setProperty form cBrackets, " ")) + (file, opt_beautifulizer) + = show_elem elem_number elem_format type file_opt_beautifulizer + = show_list (inc elem_number) form types (file <<< seperator, opt_beautifulizer) show_list elem_number form [] file = file - show_elem elem_nr form=:{form_attr_position = No} type file - = file <:: (form, type) - show_elem elem_nr form=:{form_attr_position = Yes ([pos : positions], coercions)} type file + show_elem elem_nr form=:{form_attr_position = No} type (file, opt_beautifulizer) + = writeType file opt_beautifulizer (form, type) + show_elem elem_nr form=:{form_attr_position = Yes ([pos : positions], coercions)} type (file, opt_beautifulizer) | elem_nr == pos - = file <:: ({form & form_attr_position = Yes (positions, coercions)}, type) + = writeType file opt_beautifulizer ({form & form_attr_position = Yes (positions, coercions)}, type) | pos == cNoPosition - = file <:: (form, type) - = file <:: ({form & form_attr_position = Yes ([cNoPosition], coercions)}, type) - show_elem elem_nr form=:{form_attr_position = Yes ([], coercions)} type file - = file <:: ({form & form_attr_position = Yes ([cNoPosition], coercions)}, type) - + = writeType file opt_beautifulizer (form, type) + = writeType file opt_beautifulizer ({form & form_attr_position = Yes ([cNoPosition], coercions)}, type) + show_elem elem_nr form=:{form_attr_position = Yes ([], coercions)} type (file, opt_beautifulizer) + = writeType file opt_beautifulizer ({form & form_attr_position = Yes ([cNoPosition], coercions)}, type) from compare_constructor import equal_constructor @@ -1006,10 +1064,19 @@ where = file <<< tst_result <<< " | " <<< tst_context <<< " [" <<< tst_attr_env <<< ']' = file <<< tst_args <<< " -> " <<< tst_result <<< " | " <<< tst_context <<< " [" <<< tst_attr_env <<< ']' -// MW3.. -optionalFrontPosition :: !CoercionPosition -> String -optionalFrontPosition (CP_Expression _) - = "" -optionalFrontPosition (CP_FunArg {id_name} arg_nr) - = "\"argument "+++toString arg_nr+++" of "+++id_name+++"\"" -// ..MW3 +// MW4.. +:: TypeVarBeautifulizer = + { tvb_visited :: ![(Type, String)] + // associates type variables with strings, the type should be only GTV, TV, TempV, TQV, TempQV, TLifted. + // (associations lists are slow but cool) + , tvb_fresh_vars :: ![String] + } + +initialTypeVarBeautifulizer :: TypeVarBeautifulizer +initialTypeVarBeautifulizer + = { tvb_visited = [], tvb_fresh_vars = fresh_vars 'a' (-1) } + where + fresh_vars 'i' i + = fresh_vars 'a' (i+1) + fresh_vars ch i + = [if (i==(-1)) (toString ch) (toString ch+++toString i): fresh_vars (inc ch) i] diff --git a/frontend/unitype.dcl b/frontend/unitype.dcl index cdb79ef..0c4f726 100644 --- a/frontend/unitype.dcl +++ b/frontend/unitype.dcl @@ -49,5 +49,3 @@ uniquenessError :: !CoercionPosition !String !*ErrorAdmin -> *ErrorAdmin liftSubstitution :: !*{! Type} !{# CommonDefs }!{# BOOLVECT } !Int !*TypeVarHeap !*TypeDefInfos -> (*{! Type}, !Int, !*TypeVarHeap, !*TypeDefInfos) -instance <<< CoercionPosition - diff --git a/frontend/unitype.icl b/frontend/unitype.icl index 7c94722..14c38ce 100644 --- a/frontend/unitype.icl +++ b/frontend/unitype.icl @@ -59,14 +59,20 @@ determineAttributeCoercions off_type dem_type coercible position subst coercions { crc_type_heaps = es_type_heaps, crc_coercions = coercions, crc_td_infos = es_td_infos} = case result of Yes positions - # error = errorHeading "Uniqueness error" error + # (error=:{ea_file}) = errorHeading "Uniqueness error" error (crc_coercions, copy_crc_coercions) = uniqueCopy crc_coercions format = { form_properties = cMarkAttribute, form_attr_position = Yes (reverse positions, copy_crc_coercions) } // MW3 was: ea_file = error.ea_file <<< " attribute at indicated position could not be coerced " <:: (format, exp_off_type) <<< '\n' - ea_file = error.ea_file <<< optionalFrontPosition position - <<< " attribute at indicated position could not be coerced " <:: (format, exp_off_type) - <<< position <<< '\n' + + ea_file = + case position of + CP_FunArg _ _ + -> ea_file <<< "\"" <<< position <<< "\" " + _ + -> ea_file + ea_file = ea_file <<< "attribute at indicated position could not be coerced " + <:: (format, exp_off_type, Yes initialTypeVarBeautifulizer) <<< '\n' -> (subst, crc_coercions, crc_td_infos, crc_type_heaps, { error & ea_file = ea_file }) @@ -726,55 +732,6 @@ where (<<<) file CT_NonUnique = file <<< "CT_NonUnique" (<<<) file CT_Empty = file <<< "##" -/* MW3 was: -instance <<< CoercionPosition -where - (<<<) file {cp_expression} = show_expression file cp_expression -*/ -instance <<< CoercionPosition -where - (<<<) file (CP_FunArg fun_ident arg_nr) = file - (<<<) file (CP_Expression expression) = show_expression (file <<< " near ") expression - where - show_expression file (Var {var_name}) - = file <<< var_name - show_expression file (FreeVar {fv_name}) - = file <<< fv_name - show_expression file (App {app_symb={symb_name}}) - = file <<< symb_name - show_expression file (fun @ fun_args) - = show_expression file fun - show_expression file (Case {case_ident}) - = case case_ident of - Yes {id_name} - # (line, pos) = get_line_and_col "_c" id_name - -> file <<< "case [" <<< line <<< ',' <<< pos <<< ']' - No - -> file <<< "(case ... )" - show_expression file (Selection _ expr selectors) - = file <<< "selection" - show_expression file (Update expr1 selectors expr2) - = file <<< "update" - show_expression file (TupleSelect {ds_arity} elem_nr expr) - = file <<< "argument" <<< (elem_nr + 1) <<< " of " <<< ds_arity <<< "-tuple" - show_expression file (BasicExpr bv _) - = file <<< bv - show_expression file (MatchExpr _ _ expr) - = file <<< "match expression" - show_expression file _ - = file - - - get_line_and_col prefix ident - # ident = ident % (0, size prefix - 1) - del_pos = find_delimiter '_' 0 ident - = (toInt (ident % (0, del_pos - 1)), toInt (ident % (del_pos + 1, size ident - 1))) - where - find_delimiter del_char del_pos ident - | del_char == ident.[del_pos] - = del_pos - = find_delimiter del_char (inc del_pos) ident - file_to_true :: !File -> Bool file_to_true file = code { .inline file_to_true |