Mantis Bugtracker
  

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0006426 [Squeak] Compiler feature always 04-18-07 14:42 04-18-10 22:06
Reporter sig View Status public  
Assigned To Keith_Hodges
Priority normal Resolution open  
Status closed   Product Version 3.9
Summary 0006426: ifNotNil: don't accept monadic blocks
Description (someObject message) ifNotNil: [ :obj | ....

<- argument of ifNotNil: must be a 0-argument block ->
]
Additional Information i don't know if this an issue, because this method used only in compiler definitions and only in one place in real code, except from mine.
Attached Files  ifNotNilFix.1.cs [^] (1,438 bytes) 06-21-07 06:47
 MonadicIfNotNil.1.cs [^] (5,255 bytes) 02-22-09 21:56
 MonadicIfNotNilTests.1.cs [^] (3,315 bytes) 02-22-09 21:56
 M6426-MonadicIfNotNil-mtf.2.cs [^] (5,265 bytes) 02-23-09 03:57

- Relationships

SYSTEM WARNING: Creating default object from empty value

child of 0004867closed nicolas cellier argument of ifNotNil: must be a 0-argument block, code does not match compiler inlining behavior 
child of 0007423new  Fixes included in Level Playing Field 

- Notes
(0010579 - 217 - 241 - 241 - 241 - 241 - 241)
wiz
04-18-07 20:35
edited on: 04-18-07 20:43

Huh? I know there is an issue here but I get confused from the description.

Can you give two examples (one that works and one that doesn't) and say again what you think should be true when this works as you wish.

 
(0010588 - 447 - 507 - 507 - 507 - 507 - 507)
sig
04-19-07 04:28

ok ok.

sample 1
(someObject message) ifNotNil: [ someOtherObject and some more code ].

sample 2

(someObject message) ifNotNil: [ :notNilValue | self now i can use: notNilValue ].

Note, both samples is correct use of this method. Because if you see #ifNotNil: implementation , it uses #valueWithPossibleArgs: method to enter block closure.
But when i compile sample 2 - compiler insists that i can use it only in form like sample 1.
 
(0010592 - 1076 - 1280 - 1280 - 1427 - 1427 - 1427)
wiz
04-19-07 19:23
edited on: 04-19-07 20:54

cool,

Now I understand.

nil ifNotNil: [ :each | nil inform: each printString <- argument of ifNotNil: must be a 0-argument block ->]

8 ifNotNil: [ nil inform: nil printString ] nil

nil ifNotNil: [ nil inform: nil printString ] nil

were my workspace examples. Confirming your point.

I seem to remember discussion along the lines of this being due to inlining (i.e. its handled as a special case by the compiler.)

So I think it would be quite hard to fix. (Compiler or vm level.)
However I maight be mistaken. Lets see if anyone else has an idea.

Ah, found the reference see 0004867.

Marcus's decision was just to change to code to follow what the compiler actually does.

So it looks like that will be the resolution.

The message #ifNotNilDo: is the form that takes and argument



Note: From the view issues page you can research past reports by putting in a search phrase (e.g. I used ifnotnil) and pressing the nearby button.

Welcome and thanks for helping improve squeak with your reports.

Yours in service, --Jerome Peace

 
(0010594 - 567 - 940 - 940 - 940 - 940 - 940)
sig
04-20-07 18:15

i dont know if #ifNotNil: described in ANSI protocol, but in VW its declared as following:

ifNotNil: aBlock
    "If the receiver is not nil, answer the evaluation of aBlock (with the receiver as
     its argument if it takes one), otherwise answer nil. Since the receiver is not nil,
     answer aBlock's evaluation. Passing the receiver to aBlock is handy for idioms
     such as
        self toolBarSpec ifNotNil: [:spec | ...].
    UndefinedObject reimplements this to not evaluate aBlock."

    ^0 == aBlock numArgs
        ifTrue: [aBlock value]
        ifFalse: [aBlock value: self]
 
(0010603 - 301 - 313 - 651 - 651 - 651 - 651)
vassili
04-23-07 09:10
edited on: 04-23-07 09:10

By an interesting coincidence I just wrote up an analysis and posted the compiler fix on my blog http://blog.3plus4.org/2007/04/22/notnil-then-what. [^] Thanks to Lukas Renggli for pointing me here. Here is a direct link to the fix: http://blog.3plus4.org/wp-content/uploads/2007/04/monadicifnotnil.zip. [^]

 
(0010607 - 229 - 247 - 247 - 247 - 247 - 247)
sig
04-23-07 15:17
edited on: 04-23-07 15:18

vassili, thanks for a long description which supports my point of view.
If #ifNotNil: accepts only nulladic blocks then there is totally no reasons to introduce it at all, because it simply can be replaced by isNil IfFalse: []

 
(0010822 - 195 - 195 - 195 - 195 - 195 - 195)
pdcawley
06-21-07 06:49

The ifNotNilFix.1.cs changeset I just uploaded contains a simple fix to the optimizer to make ifNotNil: behave as implemented without ditching the optimization where the block has zero arguments.
 
(0010824 - 77 - 101 - 101 - 101 - 101 - 101)
wiz
06-22-07 00:06

Reminder sent to: MarcusDenker

Hi marcus,

Your feedback could clinch it.

Would you recommend this fix?
 
(0012979 - 118 - 124 - 124 - 124 - 124 - 124)
MarcusDenker
02-22-09 18:50

The solution is to adopt vassili's code ASAP. (it's in Pharo since a couple of Months, in NewSpeak sind
he wrote it).
 
(0012981 - 190 - 190 - 190 - 190 - 190 - 190)
KenCausey
02-22-09 22:23

I'm just about the last person to be judging compiler changes, but in my opinion MonadicIfNotNil.1.cs addresses everything that ifNotNilFix.1.cs and more. There is no value in loading both.
 
(0012982 - 235 - 321 - 321 - 321 - 321 - 321)
matthewf
02-23-09 03:58

Fixed some underscore assignments

"fix begin"
Installer mantis bug: 6426 fix: 'M6426-MonadicIfNotNil-mtf.2.cs'. "Vassili's fix"
"fix test"
Installer mantis bug: 6426 fix: 'MonadicIfNotNilTests.1.cs'. "Vassilli's tests"
"fix end"
 

- Issue History
Date Modified Username Field Change
04-18-07 14:42 sig New Issue
04-18-07 20:35 wiz Note Added: 0010579
04-18-07 20:43 wiz Note Edited: 0010579
04-19-07 04:28 sig Note Added: 0010588
04-19-07 19:23 wiz Note Added: 0010592
04-19-07 19:24 wiz Status new => confirmed
04-19-07 19:31 wiz Relationship added child of 0004867
04-19-07 19:36 wiz Note Edited: 0010592
04-19-07 19:41 wiz Note Edited: 0010592
04-19-07 20:54 wiz Note Edited: 0010592
04-20-07 18:15 sig Note Added: 0010594
04-23-07 09:10 vassili Note Added: 0010603
04-23-07 09:10 vassili Note Edited: 0010603
04-23-07 15:17 sig Note Added: 0010607
04-23-07 15:18 sig Note Edited: 0010607
06-21-07 06:47 pdcawley File Added: ifNotNilFix.1.cs
06-21-07 06:49 pdcawley Note Added: 0010822
06-22-07 00:06 wiz Issue Monitored: MarcusDenker
06-22-07 00:06 wiz Note Added: 0010824
10-03-07 23:40 lewis Issue Monitored: lewis
02-22-09 18:50 MarcusDenker Note Added: 0012979
02-22-09 21:56 Keith_Hodges File Added: MonadicIfNotNil.1.cs
02-22-09 21:56 Keith_Hodges File Added: MonadicIfNotNilTests.1.cs
02-22-09 21:57 Keith_Hodges Note Added: 0012980
02-22-09 22:06 Keith_Hodges Note Edited: 0012980
02-22-09 22:12 Keith_Hodges Note Edited: 0012980
02-22-09 22:23 KenCausey Note Added: 0012981
02-22-09 22:31 Keith_Hodges Note Edited: 0012980
02-23-09 03:57 matthewf File Added: M6426-MonadicIfNotNil-mtf.2.cs
02-23-09 03:58 matthewf Note Added: 0012982
02-23-09 06:52 Keith_Hodges Note Deleted: 0012980
02-23-09 06:52 Keith_Hodges Status confirmed => assigned
02-23-09 06:52 Keith_Hodges Assigned To  => Keith_Hodges
02-23-09 06:52 Keith_Hodges Status assigned => resolved
02-23-09 06:52 Keith_Hodges Fixed in Version  => 3.10.2bc
11-28-09 02:26 matthewf Relationship added child of 0007423
04-18-10 22:06 andreas Status resolved => closed


Mantis 1.0.8[^]
Copyright © 2000 - 2007 Mantis Group
141 total queries executed.
64 unique queries executed.
Powered by Mantis Bugtracker