Skip to content
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

Make obsolete implicit save for procedure variables (change default semantics) #12

Closed
zbeekman opened this issue Jul 21, 2017 · 9 comments

Comments

@zbeekman
Copy link
Member

I have never met anyone who told me they need, want, or use the implicit save attribute attached to assigning default values during variable declaration. Although, in the case of modules, I think maybe it should stay? TBH, I'm confused by the semantics of save module variables.

Current behavior:

module func_mod
  implicit none
contains
  function foo(a) result(res)
    integer, intent(in) :: a
    integer :: res
    real(kind=REAL64) :: save_var=42
    res = save_var + a
    save_var = a
  end function
end module

program main
  use fun_mod
  implicit none
  print*, foo(10) ! this evaluates to 52
  print*, foo(1)  ! this evaluates to 11
end program

Desired behavior:

module func_mod
  implicit none
contains
  function foo(a) result(res)
    integer, intent(in) :: a
    integer :: res
    real(kind=REAL64) :: non_save_var=42
    res = non_save_var + a
    non_save_var = a
  end function
end module

program main
  use fun_mod
  implicit none
  print*, foo(10) ! this evaluates to 52
  print*, foo(1)  ! this evaluates to 43
end program
@milancurcic
Copy link

milancurcic commented Jul 21, 2017

One great aspect of pure attribute is that it prohibits the implicit save behavior. Unfortunately, it also prohibits initializing variables on declaration. I tend to avoid this by always initializing on separate line.

As an idea I support this, but it won't work because it breaks backward compatibility - an important feature of Fortran in comparison to many other languages.

@zbeekman
Copy link
Member Author

zbeekman commented Jul 21, 2017 via email

@milancurcic
Copy link

milancurcic commented Jul 21, 2017

I don't see the analogy to realloc_lhs. That did not change the semantics of the language that was previously standard-compliant. In this case, you are asking to change the semantics of the same syntactic expression. The standard will not say anything similar to "the behavior of the feature will be system or compiler dependent".

I think for your proposal to work, you would need to introduce a syntax element, perhaps

real(kind=REAL64),initialize :: non_save_var=42

which I think would only add to the confusion.

Do you know of other features that changed semantics going forward from FORTRAN 77?

@jacobwilliams
Copy link
Member

Maybe lobbying the compiler vendors to add a flag to warn about this is the best we can hope? I don't think there's much chance of the committee changing the behavior of something like this. Otherwise, some 50 year old code might not run right. :)

@zbeekman
Copy link
Member Author

@milancurcic I agree that you can't go changing semantics immediately that break old code. But plenty of language features have been marked obsolescent, as a mechanism to

  1. Discourage their use
  2. Sunset these features for possible future changes to default semantics

Perhaps I should remove the (change default semantics) portion from the proposal title.

@milancurcic
Copy link

milancurcic commented Jul 26, 2017

True, there are both obsolescent (still legal) and deleted (illegal) features of the language. That is not my point. My point is that there is no clear way to implement your proposal in its current form.

I see only two options for this proposal, depending on what you intend to achieve:

  1. Make obsolescent, and at a later time, delete variable initialization on declaration. This way you eliminate implicit save behavior from the language.

or

  1. Introduce a new syntax to initialize on declaration, like the one I suggested above. This way, implicit save remains in the language, but at least now there is a way to initialize on declaration without making it inherit the save attribute.

I am personally in favor of option 1, which is also supportive of my philosophy to use pure whenever the language allows me to. Either way, the proposal has to be revised. Do you agree?

@zbeekman
Copy link
Member Author

Sure, yes, my proposal needs updating, because it can't be implemented in a backwards compatible way in its current form. I am not disagreeing with that.

I don't love your proposed solutions, 1 or 2, because of verbosity. 1. violates D.R.Y. and 2. adds an extra attribute or similar that needs to be typed out on the local variable definition. In an ideal (yes, this is complete fantasy) world implicit save would have never entered the language, and then my original proposal would be the way things work. As you pointed out, this is not reality and likely cannot become reality, despite the fact that I have little sympathy for anyone who relies on implicit save and think that their code deserves abandoning by compilers and the standard. Harsh words perhaps, but I just don't see how this ever made any sense to anyone.

I agree that the changes to the standard to accomplish something in the same vein as this proposal will have too look like your proposed items either 1 or 2. At least with 1. there is some hope that compilers will start to warn you when you use implicitly saved variables. Any way I'm going to close this issue and either open a new one, or just accept defeat.

@rouson
Copy link

rouson commented Aug 3, 2017 via email

@Fortran-FOSS-Programmers Fortran-FOSS-Programmers locked and limited conversation to collaborators Aug 3, 2017
@zbeekman
Copy link
Member Author

zbeekman commented Aug 3, 2017

See #15 for continued conversation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants