Skip to content

Non-monotonic recursion: typeSize -!-> typeSize #15840

Answered by owen-mc
Lslightly asked this question in Q&A
Discussion options

You must be logged in to vote

I think your problem is caused by the use of if A then B else C. That desugars to A and B or not A and C. This introduces lots of nots, and I guess an odd number of them are getting into the recursion. It's a bit nicer to rewrite it without if then else, since most of your conditions are mutually exclusive. This works for me:

language[monotonicAggregates]
int typeSize(Type type) {
  exists(Type t | type.getUnderlyingType() = t |
    t instanceof BoolType and
    result = 8
    or
    t instanceof IntegerType and
    result = 8
    or
    t instanceof UintptrType and
    result = 8
    or
    t instanceof NumericType and
    not t instanceof IntegerType and
    result = t.(NumericType).get…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@Lslightly
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by Lslightly
Comment options

You must be logged in to vote
3 replies
@Lslightly
Comment options

@Lslightly
Comment options

@owen-mc
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
3 participants