Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Removed the vector "typechecking rule", whose existence made no sense. Typechecking rules should operate only on values and pattern of values. Typechecking multiple values against multiple params is now done through a specific function instead. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA3-256: |
7b9f645074e65ff800e2d54fadb6f35d |
| User & Date: | achavasse 2021-01-21 21:05:48.734 |
Context
|
2021-02-01
| ||
| 12:56 | Correctly handle references to references, plus some code cleaning. check-in: ba909d1a94 user: achavasse tags: trunk | |
|
2021-01-21
| ||
| 21:05 | Removed the vector "typechecking rule", whose existence made no sense. Typechecking rules should operate only on values and pattern of values. Typechecking multiple values against multiple params is now done through a specific function instead. check-in: 7b9f645074 user: achavasse tags: trunk | |
|
2021-01-13
| ||
| 11:46 | Sema: simplification: the "half-unification" rules don't need to be generators, they can only output one result. check-in: 3bf30e74ac user: achavasse tags: trunk | |
Changes
Changes to bs/builtins/types/constrainedfunc/invoke.cpp.
1 2 3 4 5 6 7 8 9 10 11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | - + - + |
#include "builtins/builtins.h"
using namespace goose::sema;
namespace goose::builtins
{
class ConstrainedFuncInvocationRule : public InvocationRule
{
public:
Value resolveInvocation( const Context& c, uint32_t loc, const Value& callee, const Term& args ) const final
{
|
| ︙ |
Changes to bs/builtins/types/constrainedfunc/typecheck.cpp.
| ︙ | |||
40 41 42 43 44 45 46 | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | - + |
auto callPat = BuildCallPatternFromFuncType( *ValueFromEIR( type ) );
auto rhsVal = *ValueFromEIR( rhs );
auto cfunc = FromValue< ConstrainedFunc >( rhsVal );
assert( cfunc );
auto localC = tcc;
|
| ︙ |
Changes to bs/builtins/types/func/build.cpp.
| ︙ | |||
83 84 85 86 87 88 89 | 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | - + + |
}
Term BuildCallPatternFromFuncType( const Value& funcType )
{
auto ftype = *FromValue< FuncType >( funcType );
auto apv = make_shared< Vector >();
|
| ︙ | |||
108 109 110 111 112 113 114 | 109 110 111 112 113 114 115 116 117 118 | - + |
apv->append( param );
else
apv->append( ValueToEIR( ValuePattern( TSID( computed ), type, TERM( ptr< void >() ) ) ) );
return true;
} );
|
Changes to bs/builtins/types/func/func.cpp.
| ︙ | |||
66 67 68 69 70 71 72 | 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | - + |
SubTerm(), // verif infos
SubTerm() // VarArg
)
);
assert( typeDecomp );
auto&& [kind, rtype, ptypes, vinf, varArg] = *typeDecomp;
|
| ︙ |
Changes to bs/builtins/types/func/invoke.cpp.
| ︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - + - + |
Value resolveInvocation( const Context& c, uint32_t loc, const Value& callee, const Term& args ) const final
{
optional< TypeCheckingContext > bestTCC;
optional< Term > bestSol;
bool ambiguous = false;
auto sig = GetFuncSig( callee );
|
| ︙ | |||
42 43 44 45 46 47 48 | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | - + - - - + - + |
Value invoke( const Context& c, uint32_t loc, const Value& callee, const Term& args, const Term& unifiedCallPat, TypeCheckingContext& tcc ) const final
{
auto newCallee = prepareFunc( c, 0, callee, unifiedCallPat, tcc );
if( newCallee.isPoison() )
return PoisonValue();
auto callDecomp = Decompose( unifiedCallPat,
|
| ︙ |
Changes to bs/builtins/types/func/typecheck.cpp.
| ︙ | |||
128 129 130 131 132 133 134 | 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | - + |
auto callPat = BuildArgPatternFromTFuncType( tcc.context(), *ValueFromEIR( type ) );
assert( callPat );
auto rhsVal = *ValueFromEIR( rhs );
auto sig = GetFuncSig( rhsVal );
|
| ︙ |
Changes to bs/builtins/types/localvar/localvar.cpp.
| ︙ | |||
124 125 126 127 128 129 130 | 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | - + |
// Create our arg list pattern.
auto args = VEC(
*BuildTemplateArgPattern( c, typeTExpr ),
ValueToEIR( ToValue( c.env()->extInitialize() ) )
);
|
| ︙ |
Changes to bs/builtins/types/overloadset/invoke.cpp.
| ︙ | |||
12 13 14 15 16 17 18 | 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | - + - + |
auto pOvlSet = *FromValue< ptr< OverloadSet > >( callee );
optional< TypeCheckingContext > bestTCC;
optional< Term > bestSol;
const OverloadSet::Overload* bestOvl = nullptr;
bool ambiguous = false;
|
| ︙ |
Changes to bs/builtins/types/overloadset/typecheck.cpp.
| ︙ | |||
35 36 37 38 39 40 41 | 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | - - - - - - - - - - - + |
)
);
assert( ldecomp );
auto&& [sort, type, val, locId] = *ldecomp;
auto callPat = BuildCallPatternFromFuncType( *ValueFromEIR( type ) );
|
| ︙ | |||
112 113 114 115 116 117 118 | 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | - - - - - - - - - - - + |
);
assert( ldecomp );
auto&& [sort, type, val, locId] = *ldecomp;
auto callPat = BuildArgPatternFromTFuncType( tcc.context(), *ValueFromEIR( type ) );
assert( callPat );
|
| ︙ |
Changes to bs/builtins/types/template/build.cpp.
| ︙ | |||
25 26 27 28 29 30 31 | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | - + + + + + + + + + + - - - - - - + - - - - + + + + + + + + + + - - - - - - - - + + + - - - |
return TFuncType( ValueToEIR( returnType ), v,
make_shared< vector< TermLoc > >(), make_shared< vector< TermLoc > >() );
}
optional< Term > BuildTFuncSignature( const Context& c, const TFuncType& tft )
{
auto v = make_shared< Vector >();
|
Changes to bs/builtins/types/template/instantiate.cpp.
| ︙ | |||
8 9 10 11 12 13 14 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - + - - - + - + |
{
Value InstantiateTFunc( const Context& c, const Value& callee, const Term& unifiedCallPat, const TypeCheckingContext& tcc )
{
auto tf = FromValue< TFunc >( callee );
assert( tf );
auto callDecomp = Decompose( unifiedCallPat,
|
| ︙ |
Changes to bs/builtins/types/template/invoke.cpp.
| ︙ | |||
14 15 16 17 18 19 20 | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | - - + + |
auto tf = FromValue< TFunc >( callee );
assert( tf );
optional< TypeCheckingContext > bestTCC;
optional< Term > bestSol;
bool ambiguous = false;
|
| ︙ |
Changes to bs/builtins/types/template/tc-tdecl.cpp.
1 2 3 4 5 6 7 8 9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - + - + |
#include "builtins/builtins.h"
namespace goose::builtins
{
Term BuildArgPatternFromTDecl( const TDecl& td )
{
return ValueToEIR( ValuePattern( HOLE( "_"_sid ), td.type(), HOLE( "_"_sid ) ) );
}
|
| ︙ | |||
48 49 50 51 52 53 54 | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | - - + + |
[]( const Term& lhs, TypeCheckingContext& c )
{
auto tdecl = FromValue< TDecl >( *ValueFromEIR( lhs ) );
assert( tdecl );
return HalfUnify( tdecl->type(), c );
} );
|
| ︙ | |||
99 100 101 102 103 104 105 | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | - + |
// We are replacing lhs with a different terms and re-unifying,
// so update the complexity accordingly. The structure of the tdecl
// shouldn't count, only its pattern.
tcc.subComplexity( GetComplexity( lhs ) );
tcc.addComplexity( GetComplexity( callPat ) );
|
| ︙ |
Changes to bs/builtins/types/template/typecheck.cpp.
| ︙ | |||
44 45 46 47 48 49 50 | 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | - + |
// Create a new named hole namespace to isolate holes from the passed function from those in
// the called function.
auto savedRHSNamespaceIndex = tcc.RHSNamespaceIndex();
auto localNSId = tcc.newNamespaceIndex();
tcc.setRHSNamespaceIndex( localNSId );
|
| ︙ | |||
103 104 105 106 107 108 109 | 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | - + |
// Create a new named hole namespace to isolate holes from the passed function from those in
// the called function.
auto savedRHSNamespaceIndex = tcc.RHSNamespaceIndex();
auto localNSId = tcc.newNamespaceIndex();
tcc.setRHSNamespaceIndex( localNSId );
|
| ︙ |
Changes to bs/sema/overloadset.cpp.
| ︙ | |||
10 11 12 13 14 15 16 | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | - + - - + - - - + - - - - - - - - - - + + + + - - + + - - + - + - + - + - - + - - - - - - - - - + - - |
}
bool OverloadSet::add( const Env& e, const Value& callee, const ptr< InvocationRule >& pInvRule )
{
auto signature = pInvRule->getSignature( callee );
assert( signature );
|
Changes to bs/sema/overloadset.h.
| ︙ | |||
23 24 25 26 27 28 29 | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | - + - + |
using TCGen = Generator< tuple<
Term,
const Overload&,
TypeCheckingContext
> >;
|
Changes to bs/sema/typecheck.cpp.
1 2 3 4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | + - + - + |
#include "sema.h"
namespace goose::sema
{
template< typename F >
|
| ︙ | |||
38 39 40 41 42 43 44 45 46 47 48 49 50 51 | 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | + + + + + + |
return AmbiguousTypeCheck{};
if( !bestSol )
return {};
return make_pair( move( *bestSol ), move( *bestTCC ) );
}
TypeCheckingSolution FindBestTyping( const Term& lhs, const Term& rhs, const Context& context )
{
return FindBestTyping( lhs, rhs, context,
[]( auto&& lhs, auto&& rhs, auto&& tcc ) { return TypeCheck( lhs, rhs, tcc ); } );
}
TCGen TypeCheck( const Term& lhs, const Term& rhs, const TypeCheckingContext& context )
{
const auto& rules = context.rules()->typeCheckingRules();
MatchSolution bestSol;
optional< TypeCheckingRuleSet::UniRule > bestRule;
|
| ︙ | |||
148 149 150 151 152 153 154 | 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + |
throw runtime_error( "ambiguous half-unification rule" );
if( !bestRule )
return nullopt;
return bestRule->func( lhs, context );
}
|
Changes to bs/sema/typecheck.h.
| ︙ | |||
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | + + |
<
NoUnification,
AmbiguousTypeCheck,
TCSol
>;
TypeCheckingSolution FindBestTyping( const Term& lhs, const Term& rhs, const Context& context );
TypeCheckingSolution FindBestTypingVec( const Term& lhs, const Term& rhs, const Context& context );
using TCGen = Generator< pair< Term, TypeCheckingContext > >;
TCGen TypeCheck( const Term& lhs, const Term& rhs, const TypeCheckingContext& context );
TCGen TypeCheckVec( const Term& lhs, const Term& rhs, const TypeCheckingContext& context );
TCGen Unify( const Term& lhs, const Term& rhs, const TypeCheckingContext& context );
optional< Term > HalfUnify( const Term& lhs, TypeCheckingContext& context );
}
#endif
|
Changes to bs/sema/uni-basicrules.cpp.
| ︙ | |||
15 16 17 18 19 20 21 | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | - - - - - - - - - - - - - - - - - |
if( i == ( lTerms.size() - 1 ) )
co_yield { TERM( make_shared< Vector >( move( vec ) ) ), tcc };
else
co_yield UnifyVectors( lTerms, rTerms, i + 1, vec, tcc );
}
}
|
| ︙ | |||
133 134 135 136 137 138 139 | 116 117 118 119 120 121 122 123 124 | - + - - - - - + - - - - - - - - - - - - - - - - - |
co_yield { lhs, tcc };
co_return;
}
Vector sol;
co_yield UnifyVectors( lTerms, rTerms, 0, sol, tcc );
} );
|
Changes to tests/noprelude/codegen/bitwiseops.ll.
| ︙ | |||
8 9 10 11 12 13 14 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | - + - + - + | %8 = alloca i16, align 2 store i8 %0, i8* %5, align 1 store i8 %1, i8* %6, align 1 store i16 %2, i16* %7, align 2 store i16 %3, i16* %8, align 2 %9 = load i8, i8* %5, align 1 %10 = load i8, i8* %6, align 1 |
| ︙ | |||
42 43 44 45 46 47 48 | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | - + - + | %38 = load i16, i16* %7, align 2 %39 = shl i16 %38, 4 %40 = load i16, i16* %7, align 2 %41 = ashr i16 %40, 4 ret void } |