abau / co4

COmplexity COncerned COnstraint COmpiler
GNU General Public License v3.0
2 stars 3 forks source link

Nat with larger bit width broken (by inefficiency) #36

Closed jwaldmann closed 11 years ago

jwaldmann commented 11 years ago

Test case: https://github.com/apunktbau/co4/blob/master/CO4/Test/Factor.hs constains simple binary multiplication.

Obeserved behaviour: eats huge amount of space (try replacing 24 by 32 also).

This seems terribly wrong: https://github.com/apunktbau/co4/blob/master/CO4/PreludeNat.hs#L50

instance Encodeable Nat where
  encode n = encodedConstructor (value n) (2^(width n)) []

since it seems to iterate over 2^24 values.

This inefficiency is hidden for the lower bit widths that we usually have (<= 8) but it should be fixed.

abau commented 11 years ago

fixed in https://github.com/apunktbau/co4/commit/7850bb873f170f508f98f6492245628d0bc2c557

The line you mentioned is actually correct (and efficent), but

uNat w = constructors $ replicate (2^w) $ Just []

is not, as it builds huge allocators for data with many constructors.

This commit introduces a special allocator BuiltIn n that simply allocates an EncodedAdt with n flags and no arguments.