bool is_sub_cap_and_ephemeral(ast_t* sub, ast_t* super) { ast_t* sub_cap = fetch_cap(sub); ast_t* sub_eph = ast_sibling(sub_cap); ast_t* super_cap = fetch_cap(super); ast_t* super_eph = ast_sibling(super_cap); return is_cap_sub_cap(ast_id(sub_cap), ast_id(sub_eph), ast_id(super_cap), ast_id(super_eph)); }
bool is_sub_cap_and_ephemeral(ast_t* sub, ast_t* super) { ast_t* sub_cap = fetch_cap(sub); ast_t* sub_eph = ast_sibling(sub_cap); ast_t* super_cap = fetch_cap(super); ast_t* super_eph = ast_sibling(super_cap); token_id t_sub_cap = ast_id(sub_cap); token_id t_sub_eph = ast_id(sub_eph); token_id t_super_cap = ast_id(super_cap); token_id t_super_eph = ast_id(super_eph); token_id t_alt_cap = t_sub_cap; // Adjusted for borrowing. if(t_sub_eph == TK_BORROWED) { switch(t_alt_cap) { case TK_ISO: t_alt_cap = TK_TAG; break; case TK_TRN: t_alt_cap = TK_BOX; break; case TK_ANY_GENERIC: t_alt_cap = TK_TAG; break; default: {} } } switch(t_super_eph) { case TK_EPHEMERAL: // Sub must be ephemeral if t_sub_cap != t_alt_cap. Otherwise, we don't // have to be ephemeral, since, for example, a ref can be a subtype of // a ref^, but an iso is not a subtype of an iso^. if((t_sub_cap != t_alt_cap) && (t_sub_eph != TK_EPHEMERAL)) return false; // Capability must be a sub-capability. return is_cap_sub_cap(t_sub_cap, t_super_cap); case TK_NONE: // Check the adjusted capability. return is_cap_sub_cap(t_alt_cap, t_super_cap); case TK_BORROWED: // Borrow a capability. if(t_sub_cap == t_super_cap) return true; // Or alias a capability. return is_cap_sub_cap(t_alt_cap, t_super_cap); default: {} } assert(0); return false; }
static bool is_nominal_eq_nominal(ast_t* sub, ast_t* super) { ast_t* sub_cap = fetch_cap(sub); ast_t* sub_eph = ast_sibling(sub_cap); ast_t* super_cap = fetch_cap(super); ast_t* super_eph = ast_sibling(super_cap); token_id t_sub_cap = ast_id(sub_cap); token_id t_sub_eph = ast_id(sub_eph); token_id t_super_cap = ast_id(super_cap); token_id t_super_eph = ast_id(super_eph); if((t_sub_cap != t_super_cap) || (t_sub_eph != t_super_eph)) return false; ast_t* sub_def = (ast_t*)ast_data(sub); ast_t* super_def = (ast_t*)ast_data(super); // If we are the same nominal type, our typeargs must be the same. if(sub_def == super_def) return is_eq_typeargs(sub, super); return false; }