On Sat, Jan 19, 2013 at 5:35 PM, Jon Harper <jon.harpe...@gmail.com> wrote:
> Here are my questions:
> 1) in bar1, "" like is enough to allow the compiler to infer type and
> generate code using string-nth-fast and set-string-nth-fast instead of
> nth-unsafe and set-nth-unsafe (just like using TYPED: in bar2); However, in
> foo1, { } like is not enough (but TYPED: in foo2 works). Is this normal ?
>
This is a bug. It should know that `M\ array like` returns an array. (Why
it's unable to infer that from the definition isn't immediately obvious to
meāfrom the definition of `M\ array like` it seems to me it ought to.)
Monkey-patching an `{ array } declare` onto the end of the method makes it
optimize as you'd expect.
> 2) in bar5, calling baz prevents the compiler from infering the type when
> mapping, although it clearly outputs a string. Inlining it makes the
> compiler infer again. But when the word you are calling before mapping is
> from the library (for example reverse, which uses the pattern "[ X ] keep
> like"), you can't inline it, so this prevents optimization of "pipeline"
> code that can't change the type of the data (this would only apply to final
> classes like strings or arrays, or else the output of like might be a
> subclass).
>
Factor's compiler doesn't propagate types across non-inlined call
boundaries in the general case, so unless you call one of the words the
compiler knows about (or a word that inlines down to known words), the type
information of the outputs disappears. TYPED: is probably your best bet if
you want static type optimization without inlining.
-Joe
------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. ON SALE this month only -- learn more at:
http://p.sf.net/sfu/learnmore_123012
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk