New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign constant expressions to 'static final' members #17

julianhyde opened this Issue Apr 14, 2014 · 0 comments


None yet
1 participant

julianhyde commented Apr 14, 2014

BlockBuilder is fairly good at detecting constants, for example (short) 10, code generating clients (for example optiq) will generate things like "Sales department".trim(). BlockBuilder should optimize such expressions, storing them in constant members (aka static final).

We already have a notion that literals (e.g. 1 and null) are constant, and which operators modify their lvalue (see ExpressionType.modifiesLvalue). I think we'd need a notion of which classes are constant (int.class, Integer.class, String.class, Timestamp.class, ImmutableMap.class, but not AtomicInteger.class, BigDecimal.class or Map.class) and of methods that always produce the same result given the same arguments ('same' according to Objects.equals), for example String.trim but not System.currentTimeMillis or Random.nextInt.

BlockBuilder should have a built-in list of immutable classes and deterministic methods, but clients of BlockBuilder should be able to add new ones to any given instance.

And of course any expression that is a constant member is also regarded as constant. (But beware cyclic initialization.)

With this knowledge, a BlockBuilder should be able to deduce bottom-up which expressions are constant and assign them to constant members.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment