Changes in / [de23648:07ac6d0]
- Files:
-
- 10 edited
-
libcfa/prelude/prelude-gen.cc (modified) (2 diffs)
-
src/ResolvExpr/AlternativeFinder.cc (modified) (1 diff)
-
src/ResolvExpr/ResolveAssertions.cc (modified) (6 diffs)
-
src/ResolvExpr/ResolveAssertions.h (modified) (1 diff)
-
src/ResolvExpr/TypeEnvironment.cc (modified) (4 diffs)
-
src/ResolvExpr/TypeEnvironment.h (modified) (1 diff)
-
src/ResolvExpr/Unify.cc (modified) (1 diff)
-
src/SynTree/Declaration.h (modified) (1 diff)
-
tests/.expect/completeTypeError.txt (modified) (2 diffs)
-
tests/completeTypeError.cfa (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/prelude/prelude-gen.cc
rde23648 r07ac6d0 10 10 // Created On : Sat Feb 16 08:44:58 2019 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Apr 2 17:18:24201913 // Update Count : 3712 // Last Modified On : Tue Mar 19 08:19:35 2019 13 // Update Count : 28 14 14 // 15 15 … … 118 118 { "?!=?", false, "signed int", Normal, "" }, 119 119 { "?=?", true, "", Normal, "" }, // void * LHS, zero_t RHS ??? 120 // { "*?", false, "&", Normal, " | sized(DT)" }, // & ??? 121 { "*?", false, "&", Normal, "" }, // & ??? 120 { "*?", false, "&", Normal, " | sized(DT)" }, // & ??? 122 121 123 122 { "?-?", false, "ptrdiff_t", Normal, " | sized(DT)" }, -
src/ResolvExpr/AlternativeFinder.cc
rde23648 r07ac6d0 258 258 // - necessary pre-requisite to pruning 259 259 AltList candidates; 260 std::list<std::string> errors;261 260 for ( unsigned i = 0; i < alternatives.size(); ++i ) { 262 resolveAssertions( alternatives[i], indexer, candidates , errors);261 resolveAssertions( alternatives[i], indexer, candidates ); 263 262 } 264 263 // fail early if none such 265 264 if ( mode.failFast && candidates.empty() ) { 266 265 std::ostringstream stream; 267 stream << "No alternatives with satisfiable assertions for " << expr << "\n"; 268 // << "Alternatives with failing assertions are:\n"; 269 // printAlts( alternatives, stream, 1 ); 270 for ( const auto& err : errors ) { 271 stream << err; 272 } 266 stream << "No resolvable alternatives for expression " << expr << "\n" 267 << "Alternatives with failing assertions are:\n"; 268 printAlts( alternatives, stream, 1 ); 273 269 SemanticError( expr->location, stream.str() ); 274 270 } -
src/ResolvExpr/ResolveAssertions.cc
rde23648 r07ac6d0 20 20 #include <list> // for list 21 21 #include <memory> // for unique_ptr 22 #include <sstream> // for ostringstream 23 #include <string> // for string 22 #include <string> 24 23 #include <unordered_map> // for unordered_map, unordered_multimap 25 24 #include <utility> // for move … … 28 27 #include "Alternative.h" // for Alternative, AssertionItem, AssertionList 29 28 #include "Common/FilterCombos.h" // for filterCombos 30 #include "Common/Indenter.h" // for Indenter31 29 #include "Common/utility.h" // for sort_mins 32 30 #include "ResolvExpr/RenameVars.h" // for renameTyVars … … 99 97 return { item, item.matches[i] }; 100 98 } 101 102 const DeclarationWithType* get_decl() const { return cache->at(key).deferIds[0].decl; }103 99 104 100 // sortable by key … … 368 364 static const int recursionLimit = /* 10 */ 4; 369 365 370 void resolveAssertions( Alternative& alt, const SymTab::Indexer& indexer, AltList& out , std::list<std::string>& errors) {366 void resolveAssertions( Alternative& alt, const SymTab::Indexer& indexer, AltList& out ) { 371 367 // finish early if no assertions to resolve 372 368 if ( alt.need.empty() ) { … … 389 385 for ( auto& assn : resn.need ) { 390 386 // fail early if any assertion is not resolvable 391 if ( ! resolveAssertion( assn, resn, assnCache ) ) { 392 Indenter tabs{ Indenter::tabsize, 3 }; 393 std::ostringstream ss; 394 ss << tabs << "Unsatisfiable alternative:\n"; 395 resn.alt.print( ss, ++tabs ); 396 ss << --tabs << "Could not satisfy assertion:\n"; 397 assn.decl->print( ss, ++tabs ); 398 399 errors.emplace_back( ss.str() ); 400 goto nextResn; 401 } 387 if ( ! resolveAssertion( assn, resn, assnCache ) ) goto nextResn; 402 388 } 403 389 … … 418 404 resn.deferred, 419 405 CandidateEnvMerger{ resn.alt.env, resn.alt.openVars, resn.indexer } ); 420 // fail early if no mutually-compatible assertion satisfaction421 if ( compatible.empty() ) {422 Indenter tabs{ Indenter::tabsize, 3 };423 std::ostringstream ss;424 ss << tabs << "Unsatisfiable alternative:\n";425 resn.alt.print( ss, ++tabs );426 ss << --tabs << "No mutually-compatible satisfaction for assertions:\n";427 ++tabs;428 for ( const auto& d : resn.deferred ) {429 d.get_decl()->print( ss, tabs );430 }431 432 errors.emplace_back( ss.str() );433 goto nextResn;434 }435 406 // sort by cost 436 407 CandidateCost coster{ resn.indexer }; -
src/ResolvExpr/ResolveAssertions.h
rde23648 r07ac6d0 24 24 namespace ResolvExpr { 25 25 /// Recursively resolves all assertions provided in an alternative; returns true iff succeeds 26 void resolveAssertions( Alternative& alt, const SymTab::Indexer& indexer, AltList& out , std::list<std::string>& errors);26 void resolveAssertions( Alternative& alt, const SymTab::Indexer& indexer, AltList& out ); 27 27 } // namespace ResolvExpr 28 28 -
src/ResolvExpr/TypeEnvironment.cc
rde23648 r07ac6d0 386 386 } 387 387 388 bool TypeEnvironment::bindVarToVar( TypeInstType *var1, TypeInstType *var2, 389 TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, 390 const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 388 bool TypeEnvironment::bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ) { 391 389 392 390 auto class1 = internal_lookup( var1->get_name() ); … … 430 428 class1->set_type( common ); 431 429 } 432 class1->data.isComplete |= data.isComplete;433 430 env.erase( class2 ); 434 431 } else return false; … … 438 435 class1->vars.insert( class2->vars.begin(), class2->vars.end() ); 439 436 class1->allowWidening = widen1; 440 class1->data.isComplete |= data.isComplete;441 437 env.erase( class2 ); 442 438 } else { 443 439 class2->vars.insert( class1->vars.begin(), class1->vars.end() ); 444 440 class2->allowWidening = widen2; 445 class2->data.isComplete |= data.isComplete;446 441 env.erase( class1 ); 447 442 } // if … … 450 445 class1->vars.insert( var2->get_name() ); 451 446 class1->allowWidening = widen1; 452 class1->data.isComplete |= data.isComplete;453 447 } else if ( class2 != env.end() ) { 454 448 // var1 unbound, add to class2 455 449 class2->vars.insert( var1->get_name() ); 456 450 class2->allowWidening = widen2; 457 class2->data.isComplete |= data.isComplete;458 451 } else { 459 452 // neither var bound, create new class -
src/ResolvExpr/TypeEnvironment.h
rde23648 r07ac6d0 139 139 /// Binds the type classes represented by `var1` and `var2` together; will add 140 140 /// one or both classes if needed. Returns false on failure. 141 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, TypeDecl::Data && data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer );141 bool bindVarToVar( TypeInstType *var1, TypeInstType *var2, const TypeDecl::Data & data, AssertionSet &need, AssertionSet &have, const OpenVarSet &openVars, WidenMode widenMode, const SymTab::Indexer &indexer ); 142 142 143 143 /// Disallows widening for all bindings in the environment -
src/ResolvExpr/Unify.cc
rde23648 r07ac6d0 172 172 bool isopen2 = var2 && ( entry2 != openVars.end() ); 173 173 174 if ( isopen1 && isopen2 ) { 175 if ( entry1->second.kind != entry2->second.kind ) { 176 result = false; 177 } else { 178 result = env.bindVarToVar( 179 var1, var2, TypeDecl::Data{ entry1->second, entry2->second }, needAssertions, 180 haveAssertions, openVars, widenMode, indexer ); 181 } 174 if ( isopen1 && isopen2 && entry1->second == entry2->second ) { 175 result = env.bindVarToVar( var1, var2, entry1->second, needAssertions, haveAssertions, openVars, widenMode, indexer ); 182 176 } else if ( isopen1 ) { 183 177 result = env.bindVar( var1, type2, entry1->second, needAssertions, haveAssertions, openVars, widenMode, indexer ); -
src/SynTree/Declaration.h
rde23648 r07ac6d0 211 211 TypeDecl::Kind kind; 212 212 bool isComplete; 213 214 213 Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {} 215 214 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {} 216 215 Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {} 217 Data( const Data& d1, const Data& d2 )218 : kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {}219 220 216 bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; } 221 217 bool operator!=(const Data & other) const { return !(*this == other);} -
tests/.expect/completeTypeError.txt
rde23648 r07ac6d0 1 completeTypeError.cfa:34:1 error: Cannot choose between 2 alternatives for expression 2 Generated Cast of: 3 Applying untyped: 4 Name: *? 5 ...to: 6 Name: x 1 completeTypeError.cfa:33:1 error: No reasonable alternatives for expression Applying untyped: 2 Name: *? 3 ...to: 4 Name: v 7 5 8 ... to: nothing Alternatives are: 9 Cost ( 0, 1, 2, 0, 1, -1, 0 ): Generated Cast of: 10 Application of 11 Variable Expression: *?: forall 12 DT: object type 13 function 14 ... with parameters 15 intrinsic pointer to instance of type DT (not function type) 16 ... returning 17 _retval__operator_deref: reference to instance of type DT (not function type) 18 ... with attributes: 19 Attribute with name: unused 20 21 22 ... to arguments 23 Variable Expression: x: pointer to instance of struct A with body 0 24 25 ... to: nothing 26 (types: 27 void 28 ) 29 Environment:( _80_4_DT ) -> instance of struct A with body 0 (no widening) 30 31 32 Cost ( 0, 1, 2, 0, 1, -1, 0 ): Generated Cast of: 33 Application of 34 Variable Expression: *?: forall 35 DT: object type 36 function 37 ... with parameters 38 intrinsic pointer to instance of type DT (not function type) 39 ... returning 40 _retval__operator_deref: reference to instance of type DT (not function type) 41 ... with attributes: 42 Attribute with name: unused 43 44 45 ... to arguments 46 Variable Expression: x: pointer to instance of struct B with body 1 47 48 ... to: nothing 49 (types: 50 void 51 ) 52 Environment:( _80_4_DT ) -> instance of struct B with body 1 (no widening) 53 54 6 completeTypeError.cfa:34:1 error: No reasonable alternatives for expression Applying untyped: 7 Name: *? 8 ...to: 9 Name: y 55 10 56 11 completeTypeError.cfa:35:1 error: No reasonable alternatives for expression Applying untyped: … … 69 24 Name: v 70 25 71 completeTypeError.cfa:5 9:1 error: No reasonable alternatives for expression Applying untyped:26 completeTypeError.cfa:58:1 error: No reasonable alternatives for expression Applying untyped: 72 27 Name: baz 73 28 ...to: 74 29 Name: y 75 30 76 completeTypeError.cfa: 60:1 error: No reasonable alternatives for expression Applying untyped:31 completeTypeError.cfa:59:1 error: No reasonable alternatives for expression Applying untyped: 77 32 Name: quux 78 33 ...to: 79 34 Name: y 80 35 81 completeTypeError.cfa:72:1 error: No alternatives with satisfiable assertions for Applying untyped: 36 completeTypeError.cfa:60:1 error: No reasonable alternatives for expression Applying untyped: 37 Name: *? 38 ...to: 39 Name: y 40 41 completeTypeError.cfa:72:1 error: No resolvable alternatives for expression Applying untyped: 82 42 Name: baz 83 43 ...to: 84 44 Name: z 85 45 86 Unsatisfiable alternative:46 Alternatives with failing assertions are: 87 47 Cost ( 0, 1, 0, 0, 1, -5, 0 ): Application of 88 Variable Expression: baz: forall89 T: sized object type90 ... with assertions91 ?=?: pointer to function92 ... with parameters93 reference to instance of type T (not function type)94 instance of type T (not function type)95 ... returning96 _retval__operator_assign: instance of type T (not function type)97 ... with attributes:98 Attribute with name: unused48 Variable Expression: baz: forall 49 T: sized object type 50 ... with assertions 51 ?=?: pointer to function 52 ... with parameters 53 reference to instance of type T (not function type) 54 instance of type T (not function type) 55 ... returning 56 _retval__operator_assign: instance of type T (not function type) 57 ... with attributes: 58 Attribute with name: unused 99 59 100 60 101 ?{}: pointer to function102 ... with parameters103 reference to instance of type T (not function type)104 ... returning nothing61 ?{}: pointer to function 62 ... with parameters 63 reference to instance of type T (not function type) 64 ... returning nothing 105 65 106 ?{}: pointer to function107 ... with parameters108 reference to instance of type T (not function type)109 instance of type T (not function type)110 ... returning nothing66 ?{}: pointer to function 67 ... with parameters 68 reference to instance of type T (not function type) 69 instance of type T (not function type) 70 ... returning nothing 111 71 112 ^?{}: pointer to function113 ... with parameters114 reference to instance of type T (not function type)115 ... returning nothing72 ^?{}: pointer to function 73 ... with parameters 74 reference to instance of type T (not function type) 75 ... returning nothing 116 76 117 77 118 function119 ... with parameters120 pointer to instance of type T (not function type)121 ... returning nothing78 function 79 ... with parameters 80 pointer to instance of type T (not function type) 81 ... returning nothing 122 82 123 ... to arguments124 Variable Expression: z: pointer to instance of type T (not function type)83 ... to arguments 84 Variable Expression: z: pointer to instance of type T (not function type) 125 85 126 (types: 127 void 128 ) 129 Environment:( _99_0_T ) -> instance of type T (not function type) (no widening) 130 131 Could not satisfy assertion: 132 ?=?: pointer to function 133 ... with parameters 134 reference to instance of type _99_0_T (not function type) 135 instance of type _99_0_T (not function type) 136 ... returning 137 _retval__operator_assign: instance of type _99_0_T (not function type) 138 ... with attributes: 139 Attribute with name: unused 86 (types: 87 void 88 ) 89 Environment:( _99_0_T ) -> instance of type T (not function type) (no widening) 140 90 141 91 92 -
tests/completeTypeError.cfa
rde23648 r07ac6d0 19 19 // okay 20 20 *i; 21 * y;21 *x; // picks B 22 22 *z; 23 23 foo(i); … … 32 32 // bad 33 33 *v; 34 * x; // ambiguous34 *y; 35 35 foo(v); 36 36 baz(v); … … 54 54 bar(y); 55 55 qux(y); 56 *y;57 56 58 57 // bad 59 58 baz(y); 60 59 quux(y); 60 *y; 61 61 } 62 62
Note:
See TracChangeset
for help on using the changeset viewer.